Class: Cocina::Models::Mapping::ToMods::Subject
- Inherits:
-
Object
- Object
- Cocina::Models::Mapping::ToMods::Subject
- Defined in:
- lib/cocina/models/mapping/to_mods/subject.rb
Overview
Maps subjects from cocina to MODS XML rubocop:disable Metrics/ClassLength
Constant Summary collapse
- TAG_NAME =
{ 'time' => :temporal, 'genre' => :genre, 'occupation' => :occupation }.freeze
- DEORDINAL_REGEX =
/(?<=[0-9])(?:st|nd|rd|th)/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xml:, subjects:, forms:, id_generator:) ⇒ Subject
constructor
A new instance of Subject.
- #write ⇒ Object
Constructor Details
#initialize(xml:, subjects:, forms:, id_generator:) ⇒ Subject
Returns a new instance of Subject.
25 26 27 28 29 30 |
# File 'lib/cocina/models/mapping/to_mods/subject.rb', line 25 def initialize(xml:, subjects:, forms:, id_generator:) @xml = xml @subjects = Array(subjects) @forms = forms || [] @id_generator = id_generator end |
Class Method Details
.write(xml:, subjects:, id_generator:, forms: []) ⇒ Object
21 22 23 |
# File 'lib/cocina/models/mapping/to_mods/subject.rb', line 21 def self.write(xml:, subjects:, id_generator:, forms: []) new(xml: xml, subjects: subjects, forms: forms, id_generator: id_generator).write end |
Instance Method Details
#write ⇒ Object
32 33 34 35 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 |
# File 'lib/cocina/models/mapping/to_mods/subject.rb', line 32 def write subjects.each do |subject| next if subject.type == 'map coordinates' parallel_subject_values = Array(subject.parallelValue) subject_value = subject type = nil # Make adjustments for a parallel person. if parallel_subject_values.present? && Cocina::Models::Mapping::FromMods::Contributor::ROLES.value?(subject.type) display_values, parallel_subject_values = parallel_subject_values.partition do |value| value.type == 'display' end if parallel_subject_values.size == 1 subject_value = parallel_subject_values.first parallel_subject_values = [] type = subject.type end end if parallel_subject_values.size > 1 write_parallel(subject, parallel_subject_values, alt_rep_group: id_generator.next_altrepgroup, display_values: display_values) else write_subject(subject, subject_value, display_values: display_values, type: type) end end write_cartographic end |