From f31e286f4a73c5c0f355512b0cb45c6c82088516 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 22 Jun 2013 01:13:46 -0400 Subject: v5: general code cleaning * propagate back to v4 after testing --- lib/sisu/v5/harvest_topics.rb | 158 +++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 79 deletions(-) (limited to 'lib/sisu/v5/harvest_topics.rb') diff --git a/lib/sisu/v5/harvest_topics.rb b/lib/sisu/v5/harvest_topics.rb index 7375e191..d3189639 100644 --- a/lib/sisu/v5/harvest_topics.rb +++ b/lib/sisu/v5/harvest_topics.rb @@ -163,13 +163,13 @@ module SiSU_HarvestTopics end def song the_idx=construct_book_topic_keys - the_hash=construct_book_topic_hash(the_idx) + construct_book_topic_hash(the_idx) end def capital(txt) txt_a=txt.scan(/\S+/) tx='' - txt_a.each do |txt| - tx += txt[0].chr.capitalize + txt[1,txt.length] + ' ' + txt_a.each do |t| + tx += t[0].chr.capitalize + t[1,txt.length] + ' ' end tx.strip end @@ -186,7 +186,7 @@ module SiSU_HarvestTopics names += %{#{n}, } end end - md={ filename: idx[:filename], file: idx[:file], author: names, title: idx[:title], page: idx[:page] } + { filename: idx[:filename], file: idx[:file], author: names, title: idx[:title], page: idx[:page] } end def capital_(txt) txt[0].chr.capitalize + txt[1,txt.length] @@ -217,9 +217,9 @@ module SiSU_HarvestTopics idx_array=@idx_array @idx_a=[] @the_a=[] - idx_array.each_pair do |lang,idx_array| + idx_array.each_pair do |lang,idx_arr| @@the_idx_topics[lang] ||= {} - idx_array.each do |idx| + idx_arr.each do |idx| if idx[:rough_idx] idx_lst=idx[:rough_idx].scan(/[^:]+/) else @@ -281,11 +281,11 @@ module SiSU_HarvestTopics end end end - y=@the_a.sort_by { |x| x[0] } #; y.each {|z| puts z} + @the_a.sort_by { |x| x[0] } #; y.each {|z| puts z} end - def construct_book_topic_hash(y) + def construct_book_topic_hash(t) @the_h={} - y.each do |z| + t.each do |z| x=z[0].scan(/[^|]+/) depth=x.length extract=(depth-1) @@ -302,55 +302,55 @@ module SiSU_HarvestTopics { x[0] => z[1] } end if extract >= 0 - k.each_pair do |x0,y| + k.each_pair do |x0,y0| if extract == 0 @the_h[x0] ||={ md: [] } - @the_h[x0][:md] << y + @the_h[x0][:md] << y0 else @the_h[x0] ||={} end #puts ' '*0 + x0 if extract >= 1 - y.each_pair do |x1,y| + y0.each_pair do |x1,y1| if extract == 1 @the_h[x0][x1] ||={ md: [] } - @the_h[x0][x1][:md] << y + @the_h[x0][x1][:md] << y1 else @the_h[x0][x1] ||={} end #puts ' '*1 + x1 if extract >= 2 - y.each_pair do |x2,y| + y1.each_pair do |x2,y2| if extract == 2 @the_h[x0][x1][x2] ||={ md: [] } - @the_h[x0][x1][x2][:md] << y + @the_h[x0][x1][x2][:md] << y2 else @the_h[x0][x1][x2] ||={} end #puts ' '*2 + x2 if extract >= 3 - y.each_pair do |x3,y| + y2.each_pair do |x3,y3| if extract == 3 @the_h[x0][x1][x2][x3] ||={ md: [] } - @the_h[x0][x1][x2][x3][:md] << y + @the_h[x0][x1][x2][x3][:md] << y3 else @the_h[x0][x1][x2][x3] ||={} end #puts ' '*3 + x3 if extract == 4 - y.each_pair do |x4,y| + y3.each_pair do |x4,y4| if extract == 4 @the_h[x0][x1][x2][x3][x4] ||={ md: [] } - @the_h[x0][x1][x2][x3][x4][:md] << y + @the_h[x0][x1][x2][x3][x4][:md] << y4 else @the_h[x0][x1][x2][x3][x4] ||={} end #puts ' '*4 + x4 if extract == 5 - y.each_pair do |x5,y| + y4.each_pair do |x5,y5| if extract == 5 @the_h[x0][x1][x2][x3][x4][x5] ||={ md: [] } - @the_h[x0][x1][x2][x3][x4][x5][:md] << y + @the_h[x0][x1][x2][x3][x4][x5][:md] << y5 end #puts ' '*5 + x5 end @@ -370,22 +370,22 @@ module SiSU_HarvestTopics @the_h end def traverse_base - @the_h.each_pair do |x0,y| + @the_h.each_pair do |x0,y0| puts ' '*0 + x0 if x0.is_a?(String) - if y.is_a?(Hash) - y.each_pair do |x1,y| + if y0.is_a?(Hash) + y0.each_pair do |x1,y1| puts ' '*1 + x1 if x1.is_a?(String) - if y.is_a?(Hash) - y.each_pair do |x2,y| + if y1.is_a?(Hash) + y1.each_pair do |x2,y2| puts ' '*2 + x2 if x2.is_a?(String) - if y.is_a?(Hash) - y.each_pair do |x3,y| + if y2.is_a?(Hash) + y2.each_pair do |x3,y3| puts ' '*3 + x3 if x3.is_a?(String) - if y.is_a?(Hash) - y.each_pair do |x4,y| + if y3.is_a?(Hash) + y3.each_pair do |x4,y4| puts ' '*4 + x4 if x4.is_a?(String) - if y.is_a?(Hash) - y.each_pair do |x5,y| + if y4.is_a?(Hash) + y4.each_pair do |x5,y5| puts ' '*5 + x5 if x5.is_a?(String) end end @@ -400,37 +400,37 @@ module SiSU_HarvestTopics end end def traverse - @the_h.each_pair do |x0,y| + @the_h.each_pair do |x0,y0| 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] } + if y0.is_a?(Hash) + if y0.has_key?(:md) + y0[:md].each { |x| puts ' '*5 + x[:title] } end - y.each_pair do |x1,y| + y0.each_pair do |x1,y1| 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] } + if y1.is_a?(Hash) + if y1.has_key?(:md) + y1[:md].each { |x| puts ' '*5 + x[:title] } end - y.each_pair do |x2,y| + y1.each_pair do |x2,y2| 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] } + if y2.is_a?(Hash) + if y2.has_key?(:md) + y2[:md].each { |x| puts ' '*5 + x[:title] } end - y.each_pair do |x3,y| + y2.each_pair do |x3,y3| 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] } + if y3.is_a?(Hash) + if y3.has_key?(:md) + y3[:md].each { |x| puts ' '*5 + x[:title] } end - y.each_pair do |x4,y| + y3.each_pair do |x4,y4| 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] } + if y4.is_a?(Hash) + if y4.has_key?(:md) + y4[:md].each { |x| puts ' '*5 + x[:title] } end - y.each_pair do |x5,y| + y4.each_pair do |x5,y5| puts ' '*5 + x4 if x4.is_a?(String) end end @@ -497,68 +497,68 @@ module SiSU_HarvestTopics html_file_close end def html_body_traverse - @the_idx.each_pair do |x0,y| + @the_idx.each_pair do |x0,y0| lng=x0 if x0.is_a?(String) #do_string_name(lng,'lev0',x0) #puts ' '*0 + x0 end - if y.is_a?(Hash) - if y.has_key?(:md) - y[:md].each do |x| + if y0.is_a?(Hash) + if y0.has_key?(:md) + y0[:md].each do |x| #do_hash(lng,attrib,x) #lv==0 ? #puts ' '*5 + x[:title] end end - y.each_pair do |x1,y| + y0.each_pair do |x1,y1| if x1.is_a?(String) do_string_name(lng,'lev0',x1) #puts ' '*1 + x1 end - if y.is_a?(Hash) - if y.has_key?(:md) - y[:md].each do |x| + if y1.is_a?(Hash) + if y1.has_key?(:md) + y1[:md].each do |x| do_hash(lng,0,x) #puts ' '*5 + x[:title] end end - y.each_pair do |x2,y| + y1.each_pair do |x2,y2| if x2.is_a?(String) do_string(lng,'lev1',x2) #puts ' '*2 + x2 end - if y.is_a?(Hash) - if y.has_key?(:md) - y[:md].each do |x| + if y2.is_a?(Hash) + if y2.has_key?(:md) + y2[:md].each do |x| do_hash(lng,1,x) #puts ' '*5 + x[:title] end end - y.each_pair do |x3,y| + y2.each_pair do |x3,y3| if x3.is_a?(String) do_string(lng,'lev2',x3) #puts ' '*3 + x3 end - if y.is_a?(Hash) - if y.has_key?(:md) - y[:md].each do |x| + if y3.is_a?(Hash) + if y3.has_key?(:md) + y3[:md].each do |x| do_hash(lng,2,x) #puts ' '*5 + x[:title] end end - y.each_pair do |x4,y| + y3.each_pair do |x4,y4| if x4.is_a?(String) do_string(lng,'lev3',x4) #puts ' '*4 + x4 end - if y.is_a?(Hash) - if y.has_key?(:md) - y[:md].each do |x| + if y4.is_a?(Hash) + if y4.has_key?(:md) + y4[:md].each do |x| do_hash(lng,3,x) #puts ' '*5 + x[:title] end end - y.each_pair do |x5,y| + y4.each_pair do |x5,y5| if x5.is_a?(String) do_string(lng,'lev4',x5) #puts ' '*5 + x5 @@ -595,18 +595,18 @@ module SiSU_HarvestTopics end ln=SiSU_i18n::Languages.new.language.list harvest_languages='' - @the_idx.keys.each do |lng| + @the_idx.keys.each do |lg| if @env.output_dir_structure.by? == :language - harvest_pth="../../#{lng}/manifest" + harvest_pth="../../#{lg}/manifest" file="#{harvest_pth}/topics.html" elsif @env.output_dir_structure.by? == :filetype harvest_pth='.' - file="#{harvest_pth}/topics.#{lng}.html" + file="#{harvest_pth}/topics.#{lg}.html" elsif @env.output_dir_structure.by? == :filename harvest_pth='.' - file="#{harvest_pth}/topics.#{lng}.html" + file="#{harvest_pth}/topics.#{lg}.html" end - l=ln[lng][:t] + l=ln[lg][:t] harvest_languages += %{#{l}   } end sv=SiSU_Env::InfoVersion.instance.get_version -- cgit v1.2.3