Class: Cocina::Models::Mapping::ToMods::NameWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/mapping/to_mods/name_writer.rb

Overview

Writes MODS XML name elements from cocina contributor

Constant Summary collapse

NAME_TYPE =

one way mapping: MODS ‘corporate’ already maps to Cocina ‘organization’

Cocina::Models::Mapping::FromMods::Contributor::ROLES.invert.freeze
NAME_PART =
Cocina::Models::Mapping::FromMods::Contributor::NAME_PART.invert.merge('activity dates' => 'date').freeze
UNCITED_DESCRIPTION =
'not included in citation'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml:, contributor:, id_generator:, name_title_vals_index: {}) ⇒ NameWriter

Returns a new instance of NameWriter.



28
29
30
31
32
33
# File 'lib/cocina/models/mapping/to_mods/name_writer.rb', line 28

def initialize(xml:, contributor:, id_generator:, name_title_vals_index: {})
  @xml = xml
  @contributor = contributor
  @id_generator = id_generator
  @name_title_vals_index = name_title_vals_index
end

Class Method Details

.write(xml:, contributor:, id_generator:, name_title_vals_index: {}) ⇒ Object



23
24
25
26
# File 'lib/cocina/models/mapping/to_mods/name_writer.rb', line 23

def self.write(xml:, contributor:, id_generator:, name_title_vals_index: {})
  new(xml: xml, contributor: contributor, id_generator: id_generator,
      name_title_vals_index: name_title_vals_index).write
end

Instance Method Details

#writeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocina/models/mapping/to_mods/name_writer.rb', line 35

def write
  if contributor.type == 'unspecified others'
    write_etal
  elsif contributor.name.present?
    # Expect contributor to have a single value for name property
    contrib_name = contributor.name.first
    parallel_name_values = contrib_name.parallelValue
    if parallel_name_values.present?
      write_contributor_with_parallel_names(parallel_name_values, contrib_name)
    else
      write_contributor(contributor)
    end
  end
end