aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v3/harvest_topics.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v3/harvest_topics.rb')
-rw-r--r--lib/sisu/v3/harvest_topics.rb130
1 files changed, 64 insertions, 66 deletions
diff --git a/lib/sisu/v3/harvest_topics.rb b/lib/sisu/v3/harvest_topics.rb
index 3487ab6b..762f4be0 100644
--- a/lib/sisu/v3/harvest_topics.rb
+++ b/lib/sisu/v3/harvest_topics.rb
@@ -104,10 +104,10 @@ module SiSU_HarvestTopics
rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m
rgx[:title]=/^@title:[ ]+(.+)/
rgx[:subtitle]=/^@title:.+?:subtitle:[ ]+(.+?)\n/m
- rgx[:idx]=/^@classify:.+?:topic_register:[ ]+(.+?)\n/m
+ rgx[:idx]=/^@classify:.+?:topic_register:[ ]+(.+?)(?:\n\n|\n\s+:\S|\n%)/m
data.each do |para|
if para=~ rgx[:idx]
- @idx_list=rgx[:idx].match(para)[1]
+ @idx_list=(rgx[:idx].match(para)[1]).split(/\s*\n\s*/).join
end
if para=~ rgx[:title]
@title=rgx[:title].match(para)[1]
@@ -118,7 +118,7 @@ module SiSU_HarvestTopics
if para=~ rgx[:author]
@author_format=rgx[:author].match(para)[1]
end
- break if @title and @subtitle and @author and @idx_lst
+ break if @title && @subtitle && @author && @idx_lst
end
@fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title
if @title \
@@ -233,8 +233,8 @@ module SiSU_HarvestTopics
end
@idx_a.each do |c|
if c.length > 1 \
- and c.class == Array
- if c[2].class == Hash
+ and c.is_a?(Array)
+ if c[2].is_a?(Hash)
c[1].each do |alt|
v=key_create(c,alt)
@the_a << [v, c[2]] if v
@@ -242,8 +242,8 @@ module SiSU_HarvestTopics
end
end
if c.length > 2 \
- and c.class == Array
- if c[3].class == Hash
+ and c.is_a?(Array)
+ if c[3].is_a?(Hash)
c[2].each do |alt|
v=key_create(c,alt)
@the_a << [v, c[3]] if v
@@ -251,8 +251,8 @@ module SiSU_HarvestTopics
end
end
if c.length > 3 \
- and c.class == Array
- if c[4].class == Hash
+ and c.is_a?(Array)
+ if c[4].is_a?(Hash)
c[3].each do |alt|
v=key_create(c,alt)
@the_a << [v, c[4]] if v
@@ -260,8 +260,8 @@ module SiSU_HarvestTopics
end
end
if c.length > 4 \
- and c.class == Array
- if c[5].class == Hash
+ and c.is_a?(Array)
+ if c[5].is_a?(Hash)
c[4].each do |alt|
v=key_create(c,alt)
@the_a << [v, c[5]] if v
@@ -269,8 +269,8 @@ module SiSU_HarvestTopics
end
end
if c.length > 5 \
- and c.class == Array
- if c[6].class == Hash
+ and c.is_a?(Array)
+ if c[6].is_a?(Hash)
c[5].each do |alt|
v=key_create(c,alt)
@the_a << [v, c[6]] if v
@@ -278,8 +278,7 @@ module SiSU_HarvestTopics
end
end
end
- y=@the_a.sort_by { |x| x[0] }
- #y.each {|z| puts z}
+ y=@the_a.sort_by { |x| x[0] } #; y.each {|z| puts z}
end
def construct_book_topic_hash(y)
@the_h={}
@@ -325,7 +324,7 @@ module SiSU_HarvestTopics
else
@the_h[x0][x1][x2] ||={}
end
- #puts ' '*2 + x2
+ #puts ' '*2 + x2
if extract >= 3
y.each_pair do |x3,y|
if extract == 3
@@ -334,7 +333,7 @@ module SiSU_HarvestTopics
else
@the_h[x0][x1][x2][x3] ||={}
end
- #puts ' '*3 + x3
+ #puts ' '*3 + x3
if extract == 4
y.each_pair do |x4,y|
if extract == 4
@@ -343,14 +342,14 @@ module SiSU_HarvestTopics
else
@the_h[x0][x1][x2][x3][x4] ||={}
end
- #puts ' '*4 + x4
+ #puts ' '*4 + x4
if extract == 5
y.each_pair do |x5,y|
if extract == 5
@the_h[x0][x1][x2][x3][x4][x5] ||={ md: [] }
@the_h[x0][x1][x2][x3][x4][x5][:md] << y
end
- #puts ' '*5 + x5
+ #puts ' '*5 + x5
end
end
end
@@ -369,22 +368,22 @@ module SiSU_HarvestTopics
end
def traverse_base
@the_h.each_pair do |x0,y|
- puts ' '*0 + x0 if x0.class == String
- if y.class == Hash
+ puts ' '*0 + x0 if x0.is_a?(String)
+ if y.is_a?(Hash)
y.each_pair do |x1,y|
- puts ' '*1 + x1 if x1.class == String
- if y.class == Hash
+ puts ' '*1 + x1 if x1.is_a?(String)
+ if y.is_a?(Hash)
y.each_pair do |x2,y|
- puts ' '*2 + x2 if x2.class == String
- if y.class == Hash
+ puts ' '*2 + x2 if x2.is_a?(String)
+ if y.is_a?(Hash)
y.each_pair do |x3,y|
- puts ' '*3 + x3 if x3.class == String
- if y.class == Hash
+ puts ' '*3 + x3 if x3.is_a?(String)
+ if y.is_a?(Hash)
y.each_pair do |x4,y|
- puts ' '*4 + x4 if x4.class == String
- if y.class == Hash
+ puts ' '*4 + x4 if x4.is_a?(String)
+ if y.is_a?(Hash)
y.each_pair do |x5,y|
- puts ' '*5 + x5 if x5.class == String
+ puts ' '*5 + x5 if x5.is_a?(String)
end
end
end
@@ -399,37 +398,37 @@ module SiSU_HarvestTopics
end
def traverse
@the_h.each_pair do |x0,y|
- puts ' '*0 + x0 if x0.class == String
- if y.class == Hash
+ puts ' '*0 + x0 if x0.is_a?(String)
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each { |x| puts ' '*5 + x[:title] }
end
y.each_pair do |x1,y|
- puts ' '*1 + x1 if x1.class == String
- if y.class == Hash
+ puts ' '*1 + x1 if x1.is_a?(String)
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each { |x| puts ' '*5 + x[:title] }
end
y.each_pair do |x2,y|
- puts ' '*2 + x2 if x2.class == String
- if y.class == Hash
+ puts ' '*2 + x2 if x2.is_a?(String)
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each { |x| puts ' '*5 + x[:title] }
end
y.each_pair do |x3,y|
- puts ' '*3 + x3 if x3.class == String
- if y.class == Hash
+ puts ' '*3 + x3 if x3.is_a?(String)
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each { |x| puts ' '*5 + x[:title] }
end
y.each_pair do |x4,y|
- puts ' '*4 + x4 if x4.class == String
- if y.class == Hash
+ puts ' '*4 + x4 if x4.is_a?(String)
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each { |x| puts ' '*5 + x[:title] }
end
y.each_pair do |x5,y|
- puts ' '*5 + x4 if x4.class == String
+ puts ' '*5 + x4 if x4.is_a?(String)
end
end
end
@@ -480,7 +479,7 @@ module SiSU_HarvestTopics
def html_file_close
@the_idx.keys.each do |lng|
@output[lng][:html].close
- @output[lng][:html_mnt].close if @output[lng][:html_mnt].class==File
+ @output[lng][:html_mnt].close if @output[lng][:html_mnt].is_a?(File)
end
end
def html_print
@@ -496,23 +495,23 @@ module SiSU_HarvestTopics
def html_body_traverse
@the_idx.each_pair do |x0,y|
lng=x0
- if x0.class == String
+ if x0.is_a?(String)
#do_string_name(lng,'lev0',x0)
#puts ' '*0 + x0
end
- if y.class == Hash
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each do |x|
- #do_hash(lng,attrib,x) #lv==0 ?
+ #do_hash(lng,attrib,x) #lv==0 ?
#puts ' '*5 + x[:title]
end
end
y.each_pair do |x1,y|
- if x1.class == String
+ if x1.is_a?(String)
do_string_name(lng,'lev0',x1)
#puts ' '*1 + x1
end
- if y.class == Hash
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each do |x|
do_hash(lng,0,x)
@@ -520,11 +519,11 @@ module SiSU_HarvestTopics
end
end
y.each_pair do |x2,y|
- if x2.class == String
+ if x2.is_a?(String)
do_string(lng,'lev1',x2)
#puts ' '*2 + x2
end
- if y.class == Hash
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each do |x|
do_hash(lng,1,x)
@@ -532,11 +531,11 @@ module SiSU_HarvestTopics
end
end
y.each_pair do |x3,y|
- if x3.class == String
+ if x3.is_a?(String)
do_string(lng,'lev2',x3)
#puts ' '*3 + x3
end
- if y.class == Hash
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each do |x|
do_hash(lng,2,x)
@@ -544,11 +543,11 @@ module SiSU_HarvestTopics
end
end
y.each_pair do |x4,y|
- if x4.class == String
+ if x4.is_a?(String)
do_string(lng,'lev3',x4)
#puts ' '*4 + x4
end
- if y.class == Hash
+ if y.is_a?(Hash)
if y.has_key?(:md)
y[:md].each do |x|
do_hash(lng,3,x)
@@ -556,7 +555,7 @@ module SiSU_HarvestTopics
end
end
y.each_pair do |x5,y|
- if x5.class == String
+ if x5.is_a?(String)
do_string(lng,'lev4',x5)
#puts ' '*5 + x5
end
@@ -667,7 +666,7 @@ WOK
</html>
WOK
@the_idx.keys.each do |lng|
- @output[lng][:html_mnt] << a if @output[lng][:html_mnt].class==File
+ @output[lng][:html_mnt] << a if @output[lng][:html_mnt].is_a?(File)
@output[lng][:html] << a
end
end
@@ -675,12 +674,12 @@ WOK
@output[lng][:html] << html
end
def do_html_maintenance(lng,html)
- @output[lng][:html_mnt] << html if @output[lng][:html_mnt].class==File
+ @output[lng][:html_mnt] << html if @output[lng][:html_mnt].is_a?(File)
end
def do_string(lng,attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
do_html(lng,html)
- do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File
+ do_html_maintenance(lng,html) if @output[lng][:html_mnt].is_a?(File)
end
def do_string_default(lng,attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
@@ -688,7 +687,7 @@ WOK
end
def do_string_maintenance(lng,attrib,string)
html=%{<p class="#{attrib}">#{string}</p>}
- do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File
+ do_html_maintenance(lng,html) if @output[lng][:html_mnt].is_a?(File)
end
def do_string_name(lng,attrib,string)
f=/^(\S)/.match(string)[1]
@@ -701,7 +700,7 @@ WOK
while @letter < f
if @alph.length > 0
@letter=@alph.shift
- if @output[lng][:html_mnt].class==File
+ if @output[lng][:html_mnt].is_a?(File)
@output[lng][:html_mnt] << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
end
@output[lng][:html] << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>}
@@ -712,7 +711,7 @@ WOK
name=string.strip.gsub(/\s+/,'_')
html=%{<p class="#{attrib}"><a name="#{name}">#{string}</a></p>}
do_html(lng,html)
- do_html_maintenance(lng,html) if @output[lng][:html_mnt].class==File
+ do_html_maintenance(lng,html) if @output[lng][:html_mnt].is_a?(File)
end
def do_array(lng,lv,array)
lv+=1
@@ -733,7 +732,7 @@ WOK
do_string_default(lng,attrib,html)
end
def do_hash_md_maintenance(lng,attrib,hash)
- if @output[lng][:html_mnt].class==File #should not be run for presentation output
+ if @output[lng][:html_mnt].is_a?(File) #should not be run for presentation output
html=%{[<a href="#{hash[:file]}.sst">src</a>]&nbsp;&nbsp;<a href="file://#{@env.path.output}/#{hash[:file]}/#{hash[:page]}">#{hash[:title]}</a> - #{hash[:author]}}
do_string_maintenance(lng,attrib,html)
end
@@ -765,16 +764,15 @@ WOK
end
end
def do_case(lng,lv,a)
- y = a.class
- case
- when y==String
+ case a
+ when String
attrib="lev#{lv}"
if a=~/S/
lv==0 ? do_string_name(lng,attrib,a) : do_string(lng,attrib,a)
end
- when y==Array
+ when Array
do_array(lng,lv,a)
- when y==Hash
+ when Hash
do_hash(lng,lv,a)
end
end