Class: Cocina::Models::Mapping::FromMods::DescriptionBuilder
- Inherits:
-
Object
- Object
- Cocina::Models::Mapping::FromMods::DescriptionBuilder
- Defined in:
- lib/cocina/models/mapping/from_mods/description_builder.rb
Overview
Creates Cocina Description objects from MODS resource element.
Constant Summary collapse
- BUILDERS =
{ note: Note, language: Language, contributor: Contributor, event: Event, subject: Subject, form: Form, identifier: Identifier, adminMetadata: AdminMetadata, relatedResource: RelatedResource, geographic: Geographic, access: Access }.freeze
Instance Attribute Summary collapse
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
Class Method Summary collapse
-
.build(resource_element:, notifier:, title_builder: Title, purl: nil) ⇒ Hash
A hash that can be mapped to a cocina description model.
Instance Method Summary collapse
-
#build(resource_element:, purl: nil, require_title: true) ⇒ Hash
A hash that can be mapped to a cocina description model.
-
#initialize(notifier:, title_builder: Title) ⇒ DescriptionBuilder
constructor
A new instance of DescriptionBuilder.
Constructor Details
#initialize(notifier:, title_builder: Title) ⇒ DescriptionBuilder
Returns a new instance of DescriptionBuilder.
35 36 37 38 |
# File 'lib/cocina/models/mapping/from_mods/description_builder.rb', line 35 def initialize(notifier:, title_builder: Title) @title_builder = title_builder @notifier = notifier end |
Instance Attribute Details
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
9 10 11 |
# File 'lib/cocina/models/mapping/from_mods/description_builder.rb', line 9 def notifier @notifier end |
Class Method Details
.build(resource_element:, notifier:, title_builder: Title, purl: nil) ⇒ Hash
Returns a hash that can be mapped to a cocina description model.
30 31 32 33 |
# File 'lib/cocina/models/mapping/from_mods/description_builder.rb', line 30 def self.build(resource_element:, notifier:, title_builder: Title, purl: nil) new(title_builder: title_builder, notifier: notifier).build(resource_element: resource_element, purl: purl) end |
Instance Method Details
#build(resource_element:, purl: nil, require_title: true) ⇒ Hash
Returns a hash that can be mapped to a cocina description model.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cocina/models/mapping/from_mods/description_builder.rb', line 41 def build(resource_element:, purl: nil, require_title: true) cocina_description = {} title_result = @title_builder.build(resource_element: resource_element, require_title: require_title, notifier: notifier) cocina_description[:title] = title_result if title_result.present? purl_value = purl || Purl.primary_purl_value(resource_element, purl) cocina_description[:purl] = purl_value if purl_value BUILDERS.each do |description_property, builder| result = builder.build(resource_element: resource_element, description_builder: self, purl: purl_value) cocina_description.merge!(description_property => result) if result.present? end cocina_description end |