Class: SiSU_HarvestAuthors::Harvest

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

Instance Method Summary collapse

Constructor Details

#initialize(opt, env, data, filename, name, idx_array, lang) ⇒ Harvest

Returns a new instance of Harvest.



107
108
109
110
# File 'lib/sisu/html_harvest_authors.rb', line 107

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

Instance Method Details

#extract_harvestObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/sisu/html_harvest_authors.rb', line 111

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