Class: Sufia::Arkivo::MetadataMunger

Inherits:
Object
  • Object
show all
Defined in:
lib/sufia/arkivo/metadata_munger.rb

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ MetadataMunger

Returns a new instance of MetadataMunger.



13
14
15
# File 'lib/sufia/arkivo/metadata_munger.rb', line 13

def initialize()
  @metadata = 
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sufia/arkivo/metadata_munger.rb', line 17

def call
  munged = {}

  # First, normalize camelCase symbols to underscore strings
  @metadata.each do |key, value|
    munged[key.to_s.underscore] = Array.wrap(value)
  end

  # Then, rename the url key to related_url
  munged['related_url'] = munged.delete('url') if munged['url']

  # Then, rename the tags key to keyword
  munged['keyword'] = munged.delete('tags') if munged['tags']

  # Then, normalize creator names
  munged_creators = munged['creators'].each do |entry|
    next if entry['name']
    entry['name'] = "#{entry.delete('lastName')}, #{entry.delete('firstName')}".strip
  end

  # Then, parse creators and contributors out
  creator_names, contributor_names = split_creators_and_contributors(munged_creators)
  munged['creator'] = creator_names unless creator_names.blank?
  munged['contributor'] = contributor_names unless contributor_names.blank?

  # And remove the original creators array
  munged.delete('creators') if munged['creators']
  munged
end