From 31d9927f356d05c24d5495bb3e4d59597bcea6eb Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 19 Dec 2009 16:28:24 -0500 Subject: minor code adjustments --- lib/sisu/v1/harvest_authors.rb | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'lib/sisu/v1/harvest_authors.rb') diff --git a/lib/sisu/v1/harvest_authors.rb b/lib/sisu/v1/harvest_authors.rb index a75c9ce8..e413b1d2 100644 --- a/lib/sisu/v1/harvest_authors.rb +++ b/lib/sisu/v1/harvest_authors.rb @@ -79,9 +79,10 @@ module HARVEST_authors file_array=[] File.open(filename,'r') do |file| file.each_line("\n\n") do |line| - if line =~/^@\S+?: / + if line =~/^@(?:title|subtitle|author|creator|date|original_publication):(?:\s|$)/m file_array << line - elsif line =~/^(?:\s*\n|%+ )/ + elsif line =~/^@\S+?:(?:\s|$)/m \ + or line =~/^(?:\s*\n|%+ )/ else break end end @@ -104,10 +105,10 @@ module HARVEST_authors @orig_pub,@title,@subtitle,@fulltitle,@author,@author_format=nil,nil,nil,nil,nil,nil @authors=[] rgx={} - rgx[:author]=/^@(?:author|creator):\s+(.+)/ + rgx[:author]=/^@(?:author|creator):(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m rgx[:title]=/^@title:\s+(.+)/ - rgx[:subtitle]=/^@subtitle:\s+(.+)/ - rgx[:date]=/^@date:\s+(\d{4})/ + rgx[:subtitle]=/^(?:@subtitle:\s+|@title:.+?:subtitle:[ ]+)(.+)/m + rgx[:date]=/^@date:(?:[ ]+|.+?:published:[ ]+)(\d{4})/m rgx[:orig_pub]=/^@original_publication:\s+(.+)/ data.each do |para| if para=~ rgx[:orig_pub] @@ -127,10 +128,7 @@ module HARVEST_authors end break if @title and @subtitle and @author and @date and @orig_pub end - @fulltitle=if @subtitle - @title + ' - ' + @subtitle - else @title - end + @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title if @title and @author_format #and @orig_pub (publication details) creator=FORMAT::Author.new(@author_format.strip).author_details @authors,@authorship=creator[:authors],creator[:authorship] @@ -144,7 +142,7 @@ module HARVEST_authors page="sisu_manifest#{lang}.html" idx_array <<= { :filename => filename, :file => file, :orig_pub => @orig_pub, :date => @date, :title => @fulltitle, :author => creator, :page => page } else - #p "missing author field: #@filename title: #@title; author: #@author_format; idx: #@orig_pub" + #p "missing author field: #{@filename} title: #{@title}; author: #{@author_format}; idx: #{@orig_pub}" end idx_array.flatten! idx_array @@ -191,7 +189,7 @@ module HARVEST_authors end def html_file_close @output[:html].close - @output[:html_mnt].close if @output[:html_mnt].class == File + @output[:html_mnt].close if @output[:html_mnt].class==File end def html_print def html_songsheet @@ -239,12 +237,9 @@ WOK a=[] a << '

' @alph.each do |x| - a << if x =~/[0-9]/; '' - else - %{#{x}, } - end + a << (x =~/[0-9]/) ? '' : %{#{x}, } end - @output[:html_mnt] << a.join if @output[:html_mnt].class == File + @output[:html_mnt] << a.join if @output[:html_mnt].class==File @output[:html] << a.join end def html_tail @@ -261,11 +256,11 @@ WOK WOK - @output[:html_mnt] << a if @output[:html_mnt].class == File + @output[:html_mnt] << a if @output[:html_mnt].class==File @output[:html] << a end def do_html(html) - @output[:html_mnt] << html if @output[:html_mnt].class == File + @output[:html_mnt] << html if @output[:html_mnt].class==File @output[:html] << html end def do_string(attrib,string) @@ -278,7 +273,7 @@ WOK while @letter < f if @alph.length > 0 @letter=@alph.shift - if @output[:html_mnt].class == File + if @output[:html_mnt].class==File @output[:html_mnt] << %{\n

#{@letter}

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

#{@letter}

} @@ -293,21 +288,21 @@ WOK do_string_name('',a) name=a[0].sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_') x = %{

#{a[0]}

} - if @output[:html_mnt].class == File + if @output[:html_mnt].class==File @output[:html_mnt] << x end @output[:html] << x works=[] a[1][:md].each do |x| work=[ "#{x[:date]} #{x[:title]}", %{

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

} ] - works<<=if @output[:html_mnt].class == File + works<<=if @output[:html_mnt].class==File work.concat([%{

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

}]) else work end end works.sort_by {|x| x[0]}.each do |x| @output[:html] << x[1] - @output[:html_mnt] << x[2] if @output[:html_mnt].class == File + @output[:html_mnt] << x[2] if @output[:html_mnt].class==File end end end -- cgit v1.2.3