class SiSU_HarvestTopics::Index

Public Class Methods

new(opt,env,idx_array,the_idx) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 192
def initialize(opt,env,idx_array,the_idx)
  @opt, @env,@idx_array,@the_idx=
    opt,env, idx_array, the_idx
  @@the_idx_topics=@the_idx
end

Public Instance Methods

capital(txt) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 201
def capital(txt)
  txt_a=txt.scan(/\S+/)
  tx=''
  txt_a.each do |t|
    tx += t[0].chr.capitalize + t[1,txt.length] + ' '
  end
  tx.strip
end
capital_(txt) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 209
def capital_(txt)
  txt[0].chr.capitalize + txt[1,txt.length]
end
construct_book_topic_hash(t) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 325
def construct_book_topic_hash(t)
  @the_h={}
  t.each do |z|
    x=z[0].scan(/[^|]+/)
    depth=x.length
    extract=(depth-1)
    k=case extract
    when 4
      { x[0] => { x[1] => { x[2] => { x[3] => { x[4] => z[1] } } } } }
    when 3
      { x[0] => { x[1] => { x[2] => { x[3] => z[1] } } } }
    when 2
      { x[0] => { x[1] => { x[2] => z[1] } } }
    when 1
      { x[0] => { x[1] => z[1] } }
    when 0
      { x[0] => z[1] }
    end
    if extract >= 0
      k.each_pair do |x0,y0|
        if extract == 0
          @the_h[x0] ||={ md: [] }
          @the_h[x0][:md] << y0
        else
          @the_h[x0] ||={}
        end
        #puts spaces*0 + x0
        if extract >= 1
          y0.each_pair do |x1,y1|
            if extract == 1
              @the_h[x0][x1] ||={ md: [] }
              @the_h[x0][x1][:md] << y1
            else
              @the_h[x0][x1] ||={}
            end
            #puts spaces*1 + x1
            if extract >= 2
              y1.each_pair do |x2,y2|
                if extract == 2
                  @the_h[x0][x1][x2] ||={ md: [] }
                  @the_h[x0][x1][x2][:md] << y2
                else
                  @the_h[x0][x1][x2] ||={}
                end
                #puts spaces*2 + x2
                if extract >= 3
                  y2.each_pair do |x3,y3|
                    if extract == 3
                      @the_h[x0][x1][x2][x3] ||={ md: [] }
                      @the_h[x0][x1][x2][x3][:md] << y3
                    else
                      @the_h[x0][x1][x2][x3] ||={}
                    end
                    #puts spaces*3 + x3
                    if extract == 4
                      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] << y4
                        else
                          @the_h[x0][x1][x2][x3][x4] ||={}
                        end
                        #puts spaces*4 + x4
                        if extract == 5
                          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] << y5
                            end
                            #puts spaces*5 + x5
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
  #@the_h.each_pair { |x,y| p x; p y }
  @the_h
end
construct_book_topic_keys() click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 255
def construct_book_topic_keys
  idx_array=@idx_array
  @idx_a=[]
  @the_a=[]
  idx_array.each_pair do |lang,idx_arr|
    @@the_idx_topics[lang] ||= {}
    idx_arr.each do |idx|
      if idx[:rough_idx]
        idx_lst=idx[:rough_idx].scan(/[^:]+/)
      else
        puts "no topic register in: << #{idx[:filename]} >>"
        next
      end
      idx_a=[]
      idx_lst.each do |c|
        idx_a << c.scan(/[^|\n]+/m)
      end
      idx_a << contents(idx,lang)
      @idx_a << [lang] + idx_a
    end
  end
  @idx_a.each do |c|
    if c.length > 1 \
    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
        end
      end
    end
    if c.length > 2 \
    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
        end
      end
    end
    if c.length > 3 \
    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
        end
      end
    end
    if c.length > 4 \
    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
        end
      end
    end
    if c.length > 5 \
    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
        end
      end
    end
  end
  @the_a.sort_by { |x| x[0] } #; y.each {|z| puts z}
end
contents(idx,lang) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 212
def contents(idx,lang)
  names=''
  idx[:author][:last_first_format_a].each do |n|
    s=n.sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_')
    names=if @env.output_dir_structure.by? == :language
      names += %{<a href="authors.html##{s}">#{n}</a>, }
    else
      names += %{<a href="authors.#{lang}.html##{s}">#{n}</a>, }
    end
  end
  {
    filename: idx[:filename],
    file: idx[:file],
    author: names,
    title: idx[:title],
    page: idx[:page]
  }
end
key_create(c,alt) click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 233
def key_create(c,alt)
  x=nil
  x=if c.length==6
    c[0].to_s + '|' +
      capital(c[1][0].to_s) + '|' +
      capital(c[2][0].to_s) + '|' +
      capital(c[3][0].to_s) + '|' +
      capital(alt.to_s)
  elsif c.length==5
    c[0].to_s + '|' +
      capital(c[1][0].to_s) + '|' +
      capital(c[2][0].to_s) + '|' +
      capital(alt.to_s)
  elsif c.length==4
    c[0].to_s + '|' +
      capital(c[1][0].to_s) + '|' +
      capital(alt.to_s)
  elsif c.length==3
    c[0].to_s + '|' +
      capital(alt.to_s)
  end
end
song() click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 197
def song
  the_idx=construct_book_topic_keys
  construct_book_topic_hash(the_idx)
end
traverse() click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 441
def traverse
  @the_h.each_pair do |x0,y0|
    puts spaces*0 + x0 if x0.is_a?(String)
    if y0.is_a?(Hash)
      if y0.has_key?(:md)
        y0[:md].each { |x| puts spaces*5 + x[:title] }
      end
      y0.each_pair do |x1,y1|
        puts spaces*1 + x1 if x1.is_a?(String)
        if y1.is_a?(Hash)
          if y1.has_key?(:md)
            y1[:md].each { |x| puts spaces*5 + x[:title] }
          end
          y1.each_pair do |x2,y2|
            puts spaces*2 + x2 if x2.is_a?(String)
            if y2.is_a?(Hash)
              if y2.has_key?(:md)
                y2[:md].each { |x| puts spaces*5 + x[:title] }
              end
              y2.each_pair do |x3,y3|
                puts spaces*3 + x3 if x3.is_a?(String)
                if y3.is_a?(Hash)
                  if y3.has_key?(:md)
                    y3[:md].each { |x| puts spaces*5 + x[:title] }
                  end
                  y3.each_pair do |x4,y4|
                    puts spaces*4 + x4 if x4.is_a?(String)
                    if y4.is_a?(Hash)
                      if y4.has_key?(:md)
                        y4[:md].each { |x| puts spaces*5 + x[:title] }
                      end
                      y4.each_pair do |x5,y5|
                        puts spaces*5 + x4 if x4.is_a?(String)
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end
traverse_base() click to toggle source
# File lib/sisu/html_harvest_topics.rb, line 411
def traverse_base
  @the_h.each_pair do |x0,y0|
    puts spaces*0 + x0 if x0.is_a?(String)
    if y0.is_a?(Hash)
      y0.each_pair do |x1,y1|
        puts spaces*1 + x1 if x1.is_a?(String)
        if y1.is_a?(Hash)
          y1.each_pair do |x2,y2|
            puts spaces*2 + x2 if x2.is_a?(String)
            if y2.is_a?(Hash)
              y2.each_pair do |x3,y3|
                puts spaces*3 + x3 if x3.is_a?(String)
                if y3.is_a?(Hash)
                  y3.each_pair do |x4,y4|
                    puts spaces*4 + x4 if x4.is_a?(String)
                    if y4.is_a?(Hash)
                      y4.each_pair do |x5,y5|
                        puts spaces*5 + x5 if x5.is_a?(String)
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end