Class: Cocina::Models::Mapping::ToMods::Title
- Inherits:
-
Object
- Object
- Cocina::Models::Mapping::ToMods::Title
- Defined in:
- lib/cocina/models/mapping/to_mods/title.rb
Overview
Maps titles from cocina to MODS XML
NOTE: contributors from nameTitleGroups are output here as well;
this allows for consistency of the nameTitleGroup number for the matching title(s) and the contributor(s)
Constant Summary collapse
- TAG_NAME =
rubocop:disable Metrics/ClassLength
Cocina::Models::Mapping::FromMods::Title::TYPES.invert.merge('activity dates' => 'date').freeze
- NAME_TYPES =
['name', 'forename', 'surname', 'life dates', 'term of address'].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml:, titles:, additional_attrs:, contributors: [], id_generator: {}) ⇒ Title
constructor
A new instance of Title.
-
#write ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/BlockLength rubocop:disable Metrics/CyclomaticComplexity.
Constructor Details
#initialize(xml:, titles:, additional_attrs:, contributors: [], id_generator: {}) ⇒ Title
Returns a new instance of Title.
24 25 26 27 28 29 30 31 |
# File 'lib/cocina/models/mapping/to_mods/title.rb', line 24 def initialize(xml:, titles:, additional_attrs:, contributors: [], id_generator: {}) @xml = xml @titles = titles @contributors = contributors @name_title_vals_index = {} @additional_attrs = additional_attrs @id_generator = id_generator end |
Class Method Details
.write(xml:, titles:, id_generator:, contributors: [], additional_attrs: {}) ⇒ Object
19 20 21 22 |
# File 'lib/cocina/models/mapping/to_mods/title.rb', line 19 def self.write(xml:, titles:, id_generator:, contributors: [], additional_attrs: {}) new(xml: xml, titles: titles, contributors: contributors, additional_attrs: additional_attrs, id_generator: id_generator).write end |
Instance Method Details
#write ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/BlockLength rubocop:disable Metrics/CyclomaticComplexity
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cocina/models/mapping/to_mods/title.rb', line 36 def write titles.each do |title| name_title_vals_index = name_title_vals_index_for(title) if title.valueAt write_xlink(title: title) elsif title.parallelValue.present? write_parallel(title: title, title_info_attrs: additional_attrs) elsif title.groupedValue.present? write_grouped(title: title, title_info_attrs: additional_attrs) elsif title.structuredValue.present? if name_title_vals_index.present? title_value_slice = Cocina::Models::Builders::NameTitleGroupBuilder.slice_of_value_or_structured_value(title.to_h) # don't leak nameTitleGroup into later titles my_additional_attrs = additional_attrs.dup my_additional_attrs[:nameTitleGroup] = name_title_group_number(title_value_slice) write_structured(title: title, title_info_attrs: my_additional_attrs.compact) else write_structured(title: title, title_info_attrs: additional_attrs.compact) end elsif title.value if name_title_vals_index.present? title_value_slice = Cocina::Models::Builders::NameTitleGroupBuilder.slice_of_value_or_structured_value(title.to_h) # don't leak nameTitleGroup into later titles my_additional_attrs = additional_attrs.dup my_additional_attrs[:nameTitleGroup] = name_title_group_number(title_value_slice) write_basic(title: title, title_info_attrs: my_additional_attrs.compact) else write_basic(title: title, title_info_attrs: additional_attrs.compact) end end associated_name = Cocina::Models::Builders::NameTitleGroupBuilder.title_value_note_slices(title).each do |value_note_slice| value_note_slice[:note]&.detect { |note| note[:type] == 'associated name' } end next if associated_name.blank? contributors.each do |contributor| if NameTitleGroup.in_name_title_group?(contributor: contributor, titles: [title]) NameWriter.write(xml: xml, contributor: contributor, name_title_vals_index: name_title_vals_index, id_generator: id_generator) end end end end |