Module: Arrolio::GenericAdapter::MetadataExtraction

Included in:
Arrolio::GenericAdapter
Defined in:
lib/arrolio/generic_adapter/metadata_extraction.rb

Overview

Extracted conversion seam (TODO 56): one module per concern, included into the adapter. The class keeps dispatch and glue.

Instance Method Summary collapse

Instance Method Details

#derive_metadata_fields(result) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arrolio/generic_adapter/metadata_extraction.rb', line 23

def (result)
  lang = result[:language].to_s
  version_date = result[:revision_date]
  year = version_date&.[](0, 4)
  result[:revision_year] = year if year&.match?(/\A\d{4}\z/)
  return if lang.empty? && version_date.nil?

  lang_initial = lang[0, 1].upcase
  year_part = year&.match?(/\A\d{4}\z/) ? "#{year} " : ''
  result[:edition_label] = "#{year_part}(#{lang_initial})"
end

#extract_cover(root) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/arrolio/generic_adapter/metadata_extraction.rb', line 35

def extract_cover(root)
   = (root)
  config = @rules['cover'] || {}
  result = {}
  (config['fields'] || ['docidentifier', 'edition', 'title_main', 'title_part']).each do |field|
    result[field.to_sym] = [field.to_sym] if [field.to_sym]
  end
  result.empty? ? nil : result
end

#extract_metadata(root) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/arrolio/generic_adapter/metadata_extraction.rb', line 8

def (root)
  config = @rules['metadata'] || {}
  bibdata_path = config['root'] || 'bibdata'
  bibdata = find_first(root, bibdata_path)
  return {} unless bibdata

  result = {}
  (config['fields'] || {}).each do |key, xpath|
    value = text_of(find_first(bibdata, xpath))
    result[key.to_sym] = value if value && !value.empty?
  end
  (result)
  result
end