Class: Sufia::Arkivo::MetadataMunger
- Inherits:
-
Object
- Object
- Sufia::Arkivo::MetadataMunger
- Defined in:
- lib/sufia/arkivo/metadata_munger.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(metadata) ⇒ MetadataMunger
constructor
A new instance of MetadataMunger.
Constructor Details
#initialize(metadata) ⇒ MetadataMunger
Returns a new instance of MetadataMunger.
15 16 17 |
# File 'lib/sufia/arkivo/metadata_munger.rb', line 15 def initialize() @metadata = end |
Instance Method Details
#call ⇒ Object
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 46 47 48 |
# File 'lib/sufia/arkivo/metadata_munger.rb', line 19 def call munged = {} # First, normalize camelCase symbols to underscore strings @metadata.each do |key, value| munged[key.to_s.underscore] = Array(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 tag munged['tag'] = 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 = munged_creators.select { |c| Sufia::Arkivo::CREATOR_TYPES.include? c['creatorType'] }.map { |c| c['name'] } contributor_names = munged_creators.select { |c| Sufia::Arkivo::CONTRIBUTOR_TYPES.include? c['creatorType'] }.map { |c| c['name'] } 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 |