Class: SiSU_HarvestTopics::Index

Inherits:
Mix
  • Object
show all
Defined in:
lib/sisu/html_harvest_topics.rb

Instance Method Summary collapse

Methods inherited from Mix

#spaces

Constructor Details

#initialize(opt, env, idx_array, the_idx) ⇒ Index

Returns a new instance of Index.



192
193
194
195
196
# 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

Instance Method Details

#capital(txt) ⇒ Object



201
202
203
204
205
206
207
208
# 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) ⇒ Object



209
210
211
# 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) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# 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_keysObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# 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) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# 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) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# 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

#songObject



197
198
199
200
# File 'lib/sisu/html_harvest_topics.rb', line 197

def song
  the_idx=construct_book_topic_keys
  construct_book_topic_hash(the_idx)
end

#traverseObject



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# 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_baseObject



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# 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