Class: Cocina::Models::Mapping::ToMods::RelatedResource

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

Overview

Maps relatedResource from cocina to MODS relatedItem

Constant Summary collapse

TYPES =
{
  'has original version' => 'original',
  'has other format' => 'otherFormat',
  'has part' => 'constituent',
  'has version' => 'otherVersion',
  'in series' => 'series',
  'part of' => 'host',
  'preceded by' => 'preceding',
  'related to' => nil, # 'related to' is a null type by design
  'reviewed by' => 'reviewOf',
  'referenced by' => 'isReferencedBy',
  'references' => 'references',
  'succeeded by' => 'succeeding'
}.freeze
DETAIL_TYPES =
{
  'location within source' => 'part',
  'volume' => 'volume',
  'issue' => 'issue',
  'chapter' => 'chapter',
  'section' => 'section',
  'paragraph' => 'paragraph',
  'track' => 'track',
  'marker' => 'marker'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml:, related_resources:, druid:, id_generator:) ⇒ RelatedResource

Returns a new instance of RelatedResource.



44
45
46
47
48
49
# File 'lib/cocina/models/mapping/to_mods/related_resource.rb', line 44

def initialize(xml:, related_resources:, druid:, id_generator:)
  @xml = xml
  @related_resources = Array(related_resources)
  @druid = druid
  @id_generator = id_generator
end

Class Method Details

.write(xml:, related_resources:, druid:, id_generator:) ⇒ Object

Parameters:



40
41
42
# File 'lib/cocina/models/mapping/to_mods/related_resource.rb', line 40

def self.write(xml:, related_resources:, druid:, id_generator:)
  new(xml: xml, related_resources: related_resources, druid: druid, id_generator: id_generator).write
end

Instance Method Details

#writeObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cocina/models/mapping/to_mods/related_resource.rb', line 51

def write
  filtered_related_resources.each do |(attributes, new_related, _orig_related)|
    xml.relatedItem attributes do
      ModsWriter.write(xml: xml, description: new_related, druid: druid,
                       id_generator: id_generator)
    end
  end

  related_resources.filter(&:valueAt).each do |related_resource|
    xml.relatedItem nil, { 'xlink:href' => related_resource.valueAt }
  end
end