Class: Cocina::Models::Mapping::ToMods::RoleWriter

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

Overview

Maps roles from cocina to MODS XML

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml:, role:) ⇒ RoleWriter

Returns a new instance of RoleWriter.



15
16
17
18
# File 'lib/cocina/models/mapping/to_mods/role_writer.rb', line 15

def initialize(xml:, role:)
  @xml = xml
  @role = role
end

Class Method Details

.write(xml:, role:) ⇒ Object



11
12
13
# File 'lib/cocina/models/mapping/to_mods/role_writer.rb', line 11

def self.write(xml:, role:)
  new(xml: xml, role: role).write
end

Instance Method Details

#writeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cocina/models/mapping/to_mods/role_writer.rb', line 20

def write
  xml.role do
    attributes = {
      valueURI: role.uri,
      authority: role.source&.code,
      authorityURI: role.source&.uri
    }.compact
    if role.value.present?
      attributes[:type] = 'text'
      value = if role.source&.value == 'Stanford self-deposit contributor types'
                role.value.downcase
              else
                role.value
              end
      xml.roleTerm value, attributes
    end
    if role.code.present?
      attributes[:type] = 'code'
      xml.roleTerm role.code, attributes
    end
  end
end