diff options
author | Ralph Amissah <ralph@amissah.com> | 2009-12-19 16:28:24 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2009-12-19 16:29:28 -0500 |
commit | 31d9927f356d05c24d5495bb3e4d59597bcea6eb (patch) | |
tree | c1299783d209bc07300986a5e560393fbb1ad2f0 /lib/sisu/v1/harvest_authors.rb | |
parent | document samples, v1 minor fixes (diff) |
minor code adjustments
Diffstat (limited to 'lib/sisu/v1/harvest_authors.rb')
-rw-r--r-- | lib/sisu/v1/harvest_authors.rb | 39 |
1 files changed, 17 insertions, 22 deletions
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 << '<p>' @alph.each do |x| - a << if x =~/[0-9]/; '' - else - %{<a href="##{x}">#{x}</a>, } - end + a << (x =~/[0-9]/) ? '' : %{<a href="##{x}">#{x}</a>, } 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 </body> </html> 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<p class="letter"><a name="#{@letter}"></p>#{@letter}</a><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>} end @output[:html] << %{\n<p class="letter"><a name="#{@letter}">#{@letter}</a></p><p class="book_index_lev1"><a name="#{@letter.downcase}"></a></p>} @@ -293,21 +288,21 @@ WOK do_string_name('',a) name=a[0].sub(/(.+?)(?:,.+|$)/,'\1').gsub(/\s+/,'_') x = %{<p class="author"><a name="#{name}">#{a[0]}</a></p>} - 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]}", %{<p class="publication">#{x[:date]} <a href="../#{x[:file]}/#{x[:page]}">#{x[:title]}</a>, #{x[:author][:authors_s]}</p>} ] - works<<=if @output[:html_mnt].class == File + works<<=if @output[:html_mnt].class==File work.concat([%{<p class="publication">[<a href="#{x[:file]}.sst">src</a>] #{x[:date]} <a href="file://#{@env.path.output}/#{x[:file]}/#{x[:page]}">#{x[:title]}</a>, #{x[:author][:authors_s]} -- [<a href="#{x[:file]}.sst">#{x[:file]}.sst</a>]</p>}]) 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 |