Class: Cocina::Models::Mapping::ToMods::Geographic

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

Overview

Maps geo extension from cocina to MODS

Constant Summary collapse

TYPE_REGEX =

rubocop:disable Metrics/ClassLength

/^type$/
MEDIA_REGEX =
/^media type$/
DATA_FORMAT_REGEX =
/^data format$/
ABOUT_URI_PREFIX =
'http://purl.stanford.edu/'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml:, geos:, druid:) ⇒ Geographic

Returns a new instance of Geographic.



21
22
23
24
25
# File 'lib/cocina/models/mapping/to_mods/geographic.rb', line 21

def initialize(xml:, geos:, druid:)
  @xml = xml
  @geos = geos
  @druid = druid
end

Class Method Details

.write(xml:, geos:, druid:) ⇒ Object



17
18
19
# File 'lib/cocina/models/mapping/to_mods/geographic.rb', line 17

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

Instance Method Details

#writeObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cocina/models/mapping/to_mods/geographic.rb', line 27

def write
  return if geos.blank?

  geos.map do |geo|
    attributes = {}
    attributes[:displayLabel] = 'geo'
    xml.extension attributes do
      xml['rdf'].RDF(format_namespace(geo)) do
        xml['rdf'].Description('rdf:about' => about(druid)) do
          add_format(extract_format(geo))
          add_type(extract_type(geo))
          add_content(geo)
        end
      end
    end
  end
end