From 64e5c9120ffb7a65b96eded0850f481e116f1d3f Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 8 Aug 2014 00:16:16 -0400 Subject: v6: use opt.act, code internals (simplify, cleaner; remove opt.cmd & opt.mod) * v5 dp, indentation changed to retain easy comparison with v6 --- lib/sisu/v6/harvest_authors.rb | 113 +++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 27 deletions(-) (limited to 'lib/sisu/v6/harvest_authors.rb') diff --git a/lib/sisu/v6/harvest_authors.rb b/lib/sisu/v6/harvest_authors.rb index 15c65813..762545c6 100644 --- a/lib/sisu/v6/harvest_authors.rb +++ b/lib/sisu/v6/harvest_authors.rb @@ -88,20 +88,36 @@ module SiSU_HarvestAuthors end lang_hash_file_array.each_pair do |lang,a| idx_array[lang] ||= [] - idx_array=SiSU_HarvestAuthors::Harvest.new(@opt,@env,a,filename,name,idx_array,lang).extract_harvest + idx_array=SiSU_HarvestAuthors::Harvest.new( + @opt, + @env, + a, + filename, + name, + idx_array, + lang + ).extract_harvest end end - the_idx=SiSU_HarvestAuthors::Index.new(idx_array,@@the_idx_authors).construct_book_author_index - SiSU_HarvestAuthors::OutputIndex.new(@opt,the_idx).html_print.html_songsheet + the_idx=SiSU_HarvestAuthors::Index.new( + idx_array, + @@the_idx_authors + ).construct_book_author_index + SiSU_HarvestAuthors::OutputIndex.new( + @opt, + the_idx + ).html_print.html_songsheet end end class Harvest def initialize(opt,env,data,filename,name,idx_array,lang) - @opt,@env,@data,@filename,@name,@idx_array,@lang=opt,env,data,filename,name,idx_array,lang + @opt, @env,@data,@filename,@name,@idx_array,@lang= + opt,env, data, filename, name, idx_array, lang end def extract_harvest - data,filename,name,idx_array,lang=@data,@filename,@name,@idx_array,@lang - @title,@subtitle,@fulltitle,@author,@author_format,@date=nil,nil,nil,nil,nil,nil + data, filename, name, idx_array, lang = + @data,@filename,@name,@idx_array,@lang + @title=@subtitle=@fulltitle=@author=@author_format=@date=nil @authors=[] rgx={} rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m @@ -123,7 +139,9 @@ module SiSU_HarvestAuthors end break if @title && @subtitle && @author && @date end - @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title + @fulltitle=@subtitle \ + ? (@title + ' - ' + @subtitle) + : @title if @title \ and @author_format creator=SiSU_FormatAuthor::Author.new(@author_format.strip).author_details @@ -138,7 +156,15 @@ module SiSU_HarvestAuthors else "sisu_manifest.#{lang}.html" end - idx_array[lang] <<= { filename: filename, file: file, date: @date, title: @fulltitle, author: creator, page: page, lang: lang } + idx_array[lang] <<= { + filename: filename, + file: file, + date: @date, + title: @fulltitle, + author: creator, + page: page, + lang: lang + } else #p "missing author field: #{@filename} title: #{@title}; author: #{@author_format}" end @@ -164,7 +190,15 @@ module SiSU_HarvestAuthors if @@the_idx_authors[lang][author].is_a?(NilClass) @@the_idx_authors[lang][author]={ md: [] } end - @@the_idx_authors[lang][author][:md] << { filename: idx[:filename], file: idx[:file], author: idx[:author], title: idx[:title], date: idx[:date], page: idx[:page], lang: idx[:lang] } + @@the_idx_authors[lang][author][:md] << { + filename: idx[:filename], + file: idx[:file], + author: idx[:author], + title: idx[:title], + date: idx[:date], + page: idx[:page], + lang: idx[:lang] + } end end end @@ -188,18 +222,26 @@ module SiSU_HarvestAuthors @output[lng] ||={} harvest_pth,file='','' if @env.output_dir_structure.by? == :language - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/#{lng}/manifest" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub + '/' \ + + lng + '/' \ + + 'manifest' file="#{harvest_pth}/authors.html" elsif @env.output_dir_structure.by? == :filetype - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}/manifest" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub + '/' \ + + 'manifest' file="#{harvest_pth}/authors.#{lng}.html" elsif @env.output_dir_structure.by? == :filename - harvest_pth="#{@env.path.webserv}/#{@opt.base_stub}" + harvest_pth=@env.path.webserv + '/' \ + + @opt.base_stub file="#{harvest_pth}/authors.#{lng}.html" end - FileUtils::mkdir_p(harvest_pth) unless FileTest.directory?(harvest_pth) + FileUtils::mkdir_p(harvest_pth) \ + unless FileTest.directory?(harvest_pth) fileinfo=(@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:urls_selected][:set]==:on \ || @opt.act[:maintenance][:set]==:on) \ ? ("file://#{file}") : '' SiSU_Screen::Ansi.new( @@ -213,7 +255,8 @@ module SiSU_HarvestAuthors def html_file_close @the_idx.keys.each do |lng| @output[lng][:html].close - @output[lng][:html_mnt].close if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt].close \ + if @output[lng][:html_mnt].is_a?(File) end end def html_print @@ -257,18 +300,22 @@ module SiSU_HarvestAuthors file="#{harvest_pth}/authors.#{lg}.html" end l=ln[lg][:t] - harvest_languages += %{#{l}   } + harvest_languages += + %{#{l}   } end sv=SiSU_Env::InfoVersion.instance.get_version if @env.output_dir_structure.by? == :language home_pth='../..' - output_structure_by='(output organised by language & filetype)' + output_structure_by= + '(output organised by language & filetype)' elsif @env.output_dir_structure.by? == :filetype home_pth='..' - output_structure_by='(output organised by filetype)' + output_structure_by= + '(output organised by filetype)' elsif @env.output_dir_structure.by? == :filename home_pth='.' - output_structure_by='(output organised by filename)' + output_structure_by= + '(output organised by filename)' else home_pth='.' output_structure_by='(output organised by ?)' @@ -301,8 +348,11 @@ WOK end def html_head @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << html_head_adjust(lng,'maintenance') if @opt.act[:maintenance][:set]==:on - @output[lng][:html] << html_head_adjust(lng) + @output[lng][:html_mnt] \ + << html_head_adjust(lng,'maintenance') \ + if @opt.act[:maintenance][:set]==:on + @output[lng][:html] \ + << html_head_adjust(lng) end end def html_alph @@ -315,7 +365,8 @@ WOK end a=a.join @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << a if @opt.act[:maintenance][:set]==:on + @output[lng][:html_mnt] << a \ + if @opt.act[:maintenance][:set]==:on @output[lng][:html] << a end end @@ -333,12 +384,14 @@ WOK WOK @the_idx.keys.each do |lng| - @output[lng][:html_mnt] << a if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt] << a \ + if @output[lng][:html_mnt].is_a?(File) @output[lng][:html] << a end end def do_html(lng,html) - @output[lng][:html_mnt] << html if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt] << html \ + if @output[lng][:html_mnt].is_a?(File) @output[lng][:html] << html end def do_string_name(lng,attrib,string) @@ -353,9 +406,11 @@ WOK if @alph.length > 0 @letter=@alph.shift if @output[lng][:html_mnt].is_a?(File) - @output[lng][:html_mnt] << %{\n

#{@letter}

} + @output[lng][:html_mnt] \ + << %{\n

#{@letter}

} end - @output[lng][:html] << %{\n

#{@letter}

} + @output[lng][:html] \ + << %{\n

#{@letter}

} else break end end @@ -383,14 +438,18 @@ WOK "./#{i[:file]}/#{i[:page]}" else '' #error end - work=[ "#{i[:date]} #{i[:title]}", %{

#{i[:date]} #{i[:title]}, #{i[:author][:authors_s]}

} ] + work=[ + "#{i[:date]} #{i[:title]}", + %{

#{i[:date]} #{i[:title]}, #{i[:author][:authors_s]}

} + ] works<<=(@output[lng][:html_mnt].is_a?(File)) \ ? (work.concat([%{

[src]  #{i[:date]} #{i[:title]}, #{i[:author][:authors_s]} -- [#{i[:file]}.sst]

}])) : work end works.sort_by {|y| y[0]}.each do |z| @output[lng][:html] << z[1] - @output[lng][:html_mnt] << z[2] if @output[lng][:html_mnt].is_a?(File) + @output[lng][:html_mnt] << z[2] \ + if @output[lng][:html_mnt].is_a?(File) end end end -- cgit v1.2.3