class SiSU_HarvestAuthors::Harvest

Public Class Methods

new(opt,env,data,filename,name,idx_array,lang) click to toggle source
# File lib/sisu/html_harvest_authors.rb, line 105
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
end

Public Instance Methods

extract_harvest() click to toggle source
# File lib/sisu/html_harvest_authors.rb, line 109
def extract_harvest
  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
  rgx[:title]=/^@title:[ ]+(.+)/
  rgx[:subtitle]=/^@title:.+?:subtitle:[ ]+(.+?)\n/m
  rgx[:date]=/^@date:(?:[ ]+|.+?:published:[ ]+)(\d{4})/m
  data.each do |para|
    if para=~ rgx[:title]
      @title=rgx[:title].match(para)[1]
    end
    if para=~ rgx[:subtitle]
      @subtitle=rgx[:subtitle].match(para)[1]
    end
    if para=~ rgx[:author]
      @author_format=rgx[:author].match(para)[1]
    end
    if para=~ rgx[:date]
      @date=rgx[:date].match(para)[1]
    end
    break if @title && @subtitle && @author && @date
  end
  @fulltitle=@subtitle \
  ? (@title + ' - ' + @subtitle)
  : @title
  if @title \
  and @author_format
    creator=SiSU_FormatAuthor::Author.new(@author_format.strip).author_details
    @authors,@authorship=creator[:authors],creator[:authorship]
    file=if name=~/~[a-z]{2,3}\.ss[mt]$/
      name.sub(/~[a-z]{2,3}\.ss[mt]$/,'')
    else
      name.sub(/\.ss[mt]$/,'')
    end
    page=if @env.output_dir_structure.by? == :language
      "#{lang}/sisu_manifest.html"
    else
      "sisu_manifest.#{lang}.html"
    end
    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
  idx_array[lang]=idx_array[lang].flatten
  idx_array
end