Class: Zizia::HyraxBasicMetadataMapper
- Inherits:
-
HashMapper
- Object
- MetadataMapper
- HashMapper
- Zizia::HyraxBasicMetadataMapper
- Defined in:
- lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb
Overview
This mapper allows you to set values for all the Hyrax fields, but depending on how you create the records, some of the values might get clobbered. For example, if you use Hyrax’s actor stack to create records, it might overwrite fields like ‘date_modified` or `depositor`.
A mapper for Hyrax metadata.
Maps from hash accessor syntax (‘[’title’]‘) to method call dot syntax (`.title`).
The fields provided by this mapper are the same as the properties defined in ‘Hyrax::CoreMetadata` and `Hyrax::BasicMetadata`.
Constant Summary collapse
- CSV_HEADERS =
If your CSV headers don’t exactly match the the method name for the property’s setter method, add a mapping here. Example: the method name is work.resource_type, but in the CSV file, the header is ‘resource type’ (without the underscore).
{ resource_type: 'resource type', description: 'abstract or summary', rights_statement: 'rights statement', date_created: 'date created', based_near: 'location', related_url: 'related url' }.freeze
Instance Attribute Summary collapse
-
#delimiter ⇒ String
The delimiter that will be used to split a metadata field into separate values.
Attributes inherited from MetadataMapper
Class Method Summary collapse
Instance Method Summary collapse
- #date_modified ⇒ Object
- #deduplication_key ⇒ Object
-
#depositor ⇒ Object
Properties defined with ‘multiple: false` in Hyrax should return a single value instead of an Array of values.
-
#fields ⇒ Enumerable<Symbol>
The fields the mapper can process.
- #files ⇒ Object
- #import_url ⇒ Object
- #label ⇒ Object
- #map_field(name) ⇒ Object
- #relative_path ⇒ Object
-
#visibility ⇒ Object
We should accept visibility values that match the UI and transform them into the controlled vocabulary term expected by Hyrax.
Methods inherited from HashMapper
Methods inherited from MetadataMapper
#field?, #method_missing, #respond_to_missing?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Zizia::MetadataMapper
Instance Attribute Details
#delimiter ⇒ String
Returns The delimiter that will be used to split a metadata field into separate values.
100 101 102 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 100 def delimiter @delimiter ||= '|~|' end |
Class Method Details
.csv_header(field) ⇒ Object
114 115 116 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 114 def self.csv_header(field) CSV_HEADERS[field.to_sym] end |
Instance Method Details
#date_modified ⇒ Object
44 45 46 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 44 def date_modified single_value('date_modified') end |
#deduplication_key ⇒ Object
60 61 62 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 60 def deduplication_key single_value('deduplication_key') end |
#depositor ⇒ Object
Properties defined with ‘multiple: false` in Hyrax should return a single value instead of an Array of values.
40 41 42 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 40 def depositor single_value('depositor') end |
#fields ⇒ Enumerable<Symbol>
Returns The fields the mapper can process.
33 34 35 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 33 def fields core_fields + basic_fields + [:visibility, :files] + zizia_fields end |
#files ⇒ Object
89 90 91 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 89 def files map_field('files') end |
#import_url ⇒ Object
56 57 58 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 56 def import_url single_value('import_url') end |
#label ⇒ Object
48 49 50 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 48 def label single_value('label') end |
#map_field(name) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 107 def map_field(name) method_name = name.to_s method_name = CSV_HEADERS[name] if CSV_HEADERS.keys.include?(name) key = matching_header(method_name) Array([key]&.split(delimiter)) end |
#relative_path ⇒ Object
52 53 54 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 52 def relative_path single_value('relative_path') end |
#visibility ⇒ Object
We should accept visibility values that match the UI and transform them into the controlled vocabulary term expected by Hyrax
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb', line 66 def visibility case [matching_header('visibility')]&.downcase&.gsub(/\s+/, "") when 'public' 'open' when 'open' 'open' when 'registered' 'authenticated' when "authenticated" 'authenticated' when ::Hyrax::Institution.name&.downcase&.gsub(/\s+/, "") 'authenticated' when ::Hyrax::Institution.name_full&.downcase&.gsub(/\s+/, "") 'authenticated' when 'private' 'restricted' when 'restricted' 'restricted' else 'restricted' # This is the default if nothing else matches end end |