Class: Cocina::Models::Mapping::FromMods::Subject

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

Overview

Maps subject elements from MODS to cocina

Constant Summary collapse

NODE_TYPE =
{
  'classification' => 'classification',
  'genre' => 'genre',
  'geographic' => 'place',
  'occupation' => 'occupation',
  'temporal' => 'time',
  'topic' => 'topic'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_element:, description_builder:) ⇒ Subject

Returns a new instance of Subject.



27
28
29
30
# File 'lib/cocina/models/mapping/from_mods/subject.rb', line 27

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

Class Method Details

.build(resource_element:, description_builder:, purl: nil) ⇒ Hash

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

Parameters:

Returns:

  • (Hash)

    a hash that can be mapped to a cocina model



23
24
25
# File 'lib/cocina/models/mapping/from_mods/subject.rb', line 23

def self.build(resource_element:, description_builder:, purl: nil)
  new(resource_element: resource_element, description_builder: description_builder).build
end

Instance Method Details

#buildObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/cocina/models/mapping/from_mods/subject.rb', line 32

def build
  altrepgroup_subject_nodes, other_subject_nodes = AltRepGroup.split(nodes: subject_nodes)

  subjects = (altrepgroup_subject_nodes.map { |subject_nodes| build_parallel_subject(subject_nodes) } +
    other_subject_nodes.filter_map { |subject_node| build_subject(subject_node) } +
    build_cartographics).compact
  Primary.adjust(subjects, 'classification', notifier, match_type: true)
  Primary.adjust(subjects.reject { |subject| subject[:type] == 'classification' }, 'subject', notifier)
  subjects
end