aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-06-19 19:21:12 -0400
committerRalph Amissah <ralph@amissah.com>2014-06-19 19:21:12 -0400
commitde1c383871c4a6e401cab30351d2af805445d5a9 (patch)
treebb5c8175624f526db846bf686cc401504b53db2a /lib
parentv5 v6: ao, code blocks, clean trailing newlines (diff)
v5 v6: ao, turn id numbers (for tags) into a hash
Diffstat (limited to 'lib')
-rw-r--r--lib/sisu/v5/ao_doc_str.rb67
-rw-r--r--lib/sisu/v6/ao_doc_str.rb67
2 files changed, 74 insertions, 60 deletions
diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb
index 59361cc8..8f708803 100644
--- a/lib/sisu/v5/ao_doc_str.rb
+++ b/lib/sisu/v5/ao_doc_str.rb
@@ -225,7 +225,14 @@ module SiSU_AO_DocumentStructureExtract
def identify_parts
tuned_file=[]
@tuned_block,@tuned_code=[],[]
- @@counter,@verse_count,@num_code_block,@num_poem,@num_group,@num_block,@num_alt,@num_table=0,0,0,0,0,0,0,0
+ @@counter,@verse_count=0,0
+ @num_id={
+ code_block: 0,
+ poem: 0,
+ group: 0,
+ alt: 0,
+ table: 0,
+ }
@metadata={}
@data.each do |t_o|
if t_o =~/^--([+~-])[#]$/
@@ -417,8 +424,8 @@ module SiSU_AO_DocumentStructureExtract
end
@@counter=1
@codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false
- @num_code_block +=1
- h={ obj: "code block start #{@num_code_block}" }
+ @num_id[:code_block] +=1
+ h={ obj: "code block start #{@num_id[:code_block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif t_o =~/^(?:poem\{|[`]{3}\s+poem)/
@@flag[:poem]=case t_o
@@ -426,8 +433,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+poem/ then :tics
else @@flag[:poem] #error
end
- @num_poem +=1
- h={ obj: "poem start #{@num_poem}" }
+ @num_id[:poem] +=1
+ h={ obj: "poem start #{@num_id[:poem]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:group\{|[`]{3}\s+group)/
@@ -436,8 +443,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+group/ then :tics
else @@flag[:group] #error
end
- @num_group +=1
- h={ obj: "group text start #{@num_group}" }
+ @num_id[:group] +=1
+ h={ obj: "group text start #{@num_id[:group]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:block\{|[`]{3}\s+block)/
@@ -446,8 +453,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+block/ then :tics
else @@flag[:block] #error
end
- @num_block +=1
- h={ obj: "block text start #{@num_block}" }
+ @num_id[:block] +=1
+ h={ obj: "block text start #{@num_id[:block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/
@@ -456,13 +463,13 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+alt/ then :tics
else @@flag[:alt] #error
end
- @num_alt +=1
- h={ obj: "alt text start #{@num_alt}" }
+ @num_id[:alt] +=1
+ h={ obj: "alt text start #{@num_id[:alt]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/
- @num_table +=1
- h={ obj: "table start #{@num_table}" }
+ @num_id[:table] +=1
+ h={ obj: "table start #{@num_id[:table]}" }
ins=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << ins
if t_o=~/^table\{(?:~h)?\s+/
@@ -516,10 +523,10 @@ module SiSU_AO_DocumentStructureExtract
width=100.00/cols
cols.times { col << width }
end
- h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/
@@ -539,10 +546,10 @@ module SiSU_AO_DocumentStructureExtract
r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
- h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
elsif t_o=~/^\{table(?:~h)?\s+/
@@ -562,10 +569,10 @@ module SiSU_AO_DocumentStructureExtract
r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
- h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
end
@@ -583,7 +590,7 @@ module SiSU_AO_DocumentStructureExtract
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h)
tuned_file << t_o
@h,@rows=nil,''
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
else
@@ -603,11 +610,11 @@ module SiSU_AO_DocumentStructureExtract
@tuned_code[-1].gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*\Z/m,'')
obj=@tuned_code.join("\n")
tags=[]
- h={ obj: obj, tags: tags, num: @num_code_block, number_: @codeblock_numbered }
+ h={ obj: obj, tags: tags, num: @num_id[:code_block], number_: @codeblock_numbered }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h)
@tuned_code=[]
tuned_file << t_o
- h={ obj: "code block end #{@num_code_block}" }
+ h={ obj: "code block end #{@num_id[:code_block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
end
if (@@flag[:code]==:curls or @@flag[:code]==:tics) \
@@ -626,37 +633,37 @@ module SiSU_AO_DocumentStructureExtract
if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \
or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:poem]=:off
- h={ obj: "poem end #{@num_poem}" }
+ h={ obj: "poem end #{@num_id[:poem]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \
or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:group]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_group }
+ h={ obj: obj, tags: tags, num: @num_id[:group] }
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h)
tuned_file << t_o
- h={ obj: "group text end #{@num_group}" }
+ h={ obj: "group text end #{@num_id[:group]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \
or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:block]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_block }
+ h={ obj: obj, tags: tags, num: @num_id[:block] }
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h)
tuned_file << t_o
- h={ obj: "block text end #{@num_block}" }
+ h={ obj: "block text end #{@num_id[:block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \
or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:alt]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_alt }
+ h={ obj: obj, tags: tags, num: @num_id[:alt] }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h)
@tuned_block=[]
tuned_file << t_o
- h={ obj: "alt text end #{@num_alt}" }
+ h={ obj: "alt text end #{@num_id[:alt]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
end
if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \
@@ -673,7 +680,7 @@ module SiSU_AO_DocumentStructureExtract
poem.each do |v|
v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n")
obj,tags=extract_tags(v)
- h={ obj: obj, tags: tags, num: @num_poem }
+ h={ obj: obj, tags: tags, num: @num_id[:poem] }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.verse(h)
tuned_file << t_o
end
diff --git a/lib/sisu/v6/ao_doc_str.rb b/lib/sisu/v6/ao_doc_str.rb
index db340aa3..ebee81aa 100644
--- a/lib/sisu/v6/ao_doc_str.rb
+++ b/lib/sisu/v6/ao_doc_str.rb
@@ -225,7 +225,14 @@ module SiSU_AO_DocumentStructureExtract
def identify_parts
tuned_file=[]
@tuned_block,@tuned_code=[],[]
- @@counter,@verse_count,@num_code_block,@num_poem,@num_group,@num_block,@num_alt,@num_table=0,0,0,0,0,0,0,0
+ @@counter,@verse_count=0,0
+ @num_id={
+ code_block: 0,
+ poem: 0,
+ group: 0,
+ alt: 0,
+ table: 0,
+ }
@metadata={}
@data.each do |t_o|
if t_o =~/^--([+~-])[#]$/
@@ -417,8 +424,8 @@ module SiSU_AO_DocumentStructureExtract
end
@@counter=1
@codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false
- @num_code_block +=1
- h={ obj: "code block start #{@num_code_block}" }
+ @num_id[:code_block] +=1
+ h={ obj: "code block start #{@num_id[:code_block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif t_o =~/^(?:poem\{|[`]{3}\s+poem)/
@@flag[:poem]=case t_o
@@ -426,8 +433,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+poem/ then :tics
else @@flag[:poem] #error
end
- @num_poem +=1
- h={ obj: "poem start #{@num_poem}" }
+ @num_id[:poem] +=1
+ h={ obj: "poem start #{@num_id[:poem]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:group\{|[`]{3}\s+group)/
@@ -436,8 +443,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+group/ then :tics
else @@flag[:group] #error
end
- @num_group +=1
- h={ obj: "group text start #{@num_group}" }
+ @num_id[:group] +=1
+ h={ obj: "group text start #{@num_id[:group]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:block\{|[`]{3}\s+block)/
@@ -446,8 +453,8 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+block/ then :tics
else @@flag[:block] #error
end
- @num_block +=1
- h={ obj: "block text start #{@num_block}" }
+ @num_id[:block] +=1
+ h={ obj: "block text start #{@num_id[:block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/
@@ -456,13 +463,13 @@ module SiSU_AO_DocumentStructureExtract
when /^[`]{3}\s+alt/ then :tics
else @@flag[:alt] #error
end
- @num_alt +=1
- h={ obj: "alt text start #{@num_alt}" }
+ @num_id[:alt] +=1
+ h={ obj: "alt text start #{@num_id[:alt]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << t_o
elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/
- @num_table +=1
- h={ obj: "table start #{@num_table}" }
+ @num_id[:table] +=1
+ h={ obj: "table start #{@num_id[:table]}" }
ins=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
tuned_file << ins
if t_o=~/^table\{(?:~h)?\s+/
@@ -516,10 +523,10 @@ module SiSU_AO_DocumentStructureExtract
width=100.00/cols
cols.times { col << width }
end
- h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/
@@ -539,10 +546,10 @@ module SiSU_AO_DocumentStructureExtract
r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
- h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
elsif t_o=~/^\{table(?:~h)?\s+/
@@ -562,10 +569,10 @@ module SiSU_AO_DocumentStructureExtract
r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}")
rows += r + Mx[:tc_c]
end
- h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_table }
+ h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags, num: @num_id[:table] }
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil?
tuned_file << t_o
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
end
@@ -583,7 +590,7 @@ module SiSU_AO_DocumentStructureExtract
t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h)
tuned_file << t_o
@h,@rows=nil,''
- h={ obj: "table end #{@num_table}" }
+ h={ obj: "table end #{@num_id[:table]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
t_o
else
@@ -603,11 +610,11 @@ module SiSU_AO_DocumentStructureExtract
@tuned_code[-1].gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*\Z/m,'')
obj=@tuned_code.join("\n")
tags=[]
- h={ obj: obj, tags: tags, num: @num_code_block, number_: @codeblock_numbered }
+ h={ obj: obj, tags: tags, num: @num_id[:code_block], number_: @codeblock_numbered }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h)
@tuned_code=[]
tuned_file << t_o
- h={ obj: "code block end #{@num_code_block}" }
+ h={ obj: "code block end #{@num_id[:code_block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
end
if (@@flag[:code]==:curls or @@flag[:code]==:tics) \
@@ -626,37 +633,37 @@ module SiSU_AO_DocumentStructureExtract
if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \
or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:poem]=:off
- h={ obj: "poem end #{@num_poem}" }
+ h={ obj: "poem end #{@num_id[:poem]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \
or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:group]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_group }
+ h={ obj: obj, tags: tags, num: @num_id[:group] }
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h)
tuned_file << t_o
- h={ obj: "group text end #{@num_group}" }
+ h={ obj: "group text end #{@num_id[:group]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \
or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:block]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_block }
+ h={ obj: obj, tags: tags, num: @num_id[:block] }
@tuned_block=[]
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h)
tuned_file << t_o
- h={ obj: "block text end #{@num_block}" }
+ h={ obj: "block text end #{@num_id[:block]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \
or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)
@@flag[:alt]=:off
obj,tags=extract_tags(@tuned_block.join("\n"))
- h={ obj: obj, tags: tags, num: @num_alt }
+ h={ obj: obj, tags: tags, num: @num_id[:alt] }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h)
@tuned_block=[]
tuned_file << t_o
- h={ obj: "alt text end #{@num_alt}" }
+ h={ obj: "alt text end #{@num_id[:alt]}" }
t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h)
end
if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \
@@ -673,7 +680,7 @@ module SiSU_AO_DocumentStructureExtract
poem.each do |v|
v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n")
obj,tags=extract_tags(v)
- h={ obj: obj, tags: tags, num: @num_poem }
+ h={ obj: obj, tags: tags, num: @num_id[:poem] }
t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.verse(h)
tuned_file << t_o
end