Class: Cocina::Models::Mapping::FromMods::TitleBuilder
- Inherits:
-
Object
- Object
- Cocina::Models::Mapping::FromMods::TitleBuilder
- Defined in:
- lib/cocina/models/mapping/from_mods/title_builder.rb
Overview
Maps titles
Class Method Summary collapse
-
.build(title_info_element:, notifier:) ⇒ Hash
A hash that can be mapped to a cocina model.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(title_info_element:, notifier:) ⇒ TitleBuilder
constructor
A new instance of TitleBuilder.
Constructor Details
#initialize(title_info_element:, notifier:) ⇒ TitleBuilder
Returns a new instance of TitleBuilder.
16 17 18 19 |
# File 'lib/cocina/models/mapping/from_mods/title_builder.rb', line 16 def initialize(title_info_element:, notifier:) @title_info_element = title_info_element @notifier = notifier end |
Class Method Details
.build(title_info_element:, notifier:) ⇒ Hash
Returns a hash that can be mapped to a cocina model.
12 13 14 |
# File 'lib/cocina/models/mapping/from_mods/title_builder.rb', line 12 def self.build(title_info_element:, notifier:) new(title_info_element: title_info_element, notifier: notifier).build end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cocina/models/mapping/from_mods/title_builder.rb', line 21 def build return { valueAt: title_info_element['xlink:href'] } if title_info_element['xlink:href'] # Find all the child nodes that have text return nil if title_info_element.children.empty? children = title_info_element.xpath('./*[child::node()[self::text()]]') if children.empty? notifier.warn('Empty title node') return nil end notifier.warn('Title with type') if children_with_type?(children) # If a displayLabel only with no title text element # Note: this is an error condition, # exceptions documented at: https://github.com/sul-dlss-labs/cocina-descriptive-metadata/blob/master/mods_cocina_mappings/mods_to_cocina_value_dependencies.txt return {} if children.map(&:name) == [] # Is this a basic title or a title with parts return simple_value(title_info_element) if simple_title?(children) structured_value(children) end |