Class: SiSU_HarvestTopics::Harvest

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Harvest.



113
114
115
116
# File 'lib/sisu/html_harvest_topics.rb', line 113

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



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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sisu/html_harvest_topics.rb', line 117

def extract_harvest
  data,   filename, name, idx_array, lang=
    @data,@filename,@name,@idx_array,@lang
  @idx_lst=@title=@subtitle=@fulltitle=@author=@author_format=nil
  rgx={}
  rgx[:author]=/^@creator:(?:[ ]+|.+?:author:[ ]+)(.+?)(?:\||\n)/m
  rgx[:title]=/^@title:[ ]+(.+)/
  rgx[:subtitle]=/^@title:.+?:subtitle:[ ]+(.+?)\n/m
  rgx[:idx]=/^@classify:.+?:topic_register:[ ]+(.+?)(?:\n\n|\n\s+:\S|\n%)/m
  data.each do |para|
    if para=~ rgx[:idx]
      @idx_list=(rgx[:idx].match(para)[1]).split(/\s*\n\s*/).join
    end
    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
    break if @title && @subtitle && @author && @idx_lst
  end
  @fulltitle=@subtitle ? (@title + ' - ' + @subtitle) : @title
  if @title \
  and @author_format \
  and @idx_list
    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] <<=if @idx_list =~/;/
      g=@idx_list.scan(/[^;]+/)
      g.each.map do |i|
        i=i.strip
        {
          filename: filename,
          file: file,
          rough_idx: i,
          title: @fulltitle,
          author: creator,
          page: page,
          lang: lang
        }
      end
    else {
        filename: filename,
        file: file,
        rough_idx: @idx_list,
        title: @fulltitle,
        author: creator,
        page: page,
        lang: lang,
      }
    end
  else
    if (@opt.act[:verbose_plus][:set]==:on \
    || @opt.act[:maintenance][:set]==:on)
      p "missing required field in #{@filename} - [title]: <<#{@title}>>; [author]: <<#{@author_format}>>; [idx]: <<#{@idx_list}>>"
    end
  end
  idx_array[lang]=idx_array[lang].flatten
  idx_array
end