Class: Cocina::Models::Mapping::FromMods::Title

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/mapping/from_mods/title.rb

Overview

Maps titles

Constant Summary collapse

TYPES =

rubocop:disable Metrics/ClassLength

{
  'nonSort' => 'nonsorting characters',
  'title' => 'main title',
  'subTitle' => 'subtitle',
  'partNumber' => 'part number',
  'partName' => 'part name',
  'date' => 'life dates',
  'given' => 'forename',
  'family' => 'surname',
  'uniform' => 'title'
}.freeze
PERSON_TYPE =
'name'
NAME_TYPES =
['person', 'forename', 'surname', 'life dates'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_element:, notifier:) ⇒ Title

Returns a new instance of Title.



33
34
35
36
# File 'lib/cocina/models/mapping/from_mods/title.rb', line 33

def initialize(resource_element:, notifier:)
  @resource_element = resource_element
  @notifier = notifier
end

Class Method Details

.build(resource_element:, notifier:, require_title: true) ⇒ Hash

Returns a hash that can be mapped to a cocina model.

Parameters:

  • resource_element (Nokogiri::XML::Element)

    mods or relatedItem element

  • require_title (boolean) (defaults to: true)

    notify if true and title is missing.

  • notifier (Cocina::Models::Mapping::ErrorNotifier)

Returns:

  • (Hash)

    a hash that can be mapped to a cocina model



29
30
31
# File 'lib/cocina/models/mapping/from_mods/title.rb', line 29

def self.build(resource_element:, notifier:, require_title: true)
  new(resource_element: resource_element, notifier: notifier).build(require_title: require_title)
end

Instance Method Details

#build(require_title: true) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cocina/models/mapping/from_mods/title.rb', line 38

def build(require_title: true)
  altrepgroup_title_info_nodes, other_title_info_nodes = AltRepGroup.split(nodes: resource_element.xpath(
    'mods:titleInfo', mods: Description::DESC_METADATA_NS
  ))

  result = altrepgroup_title_info_nodes.map { |title_info_nodes| parallel(title_info_nodes) } \
    + simple_or_structured(other_title_info_nodes)
  Primary.adjust(result, 'title', notifier)

  notifier.error('Missing title') if result.empty? && require_title

  result
end