Class: Cocina::Models::Mapping::FromMods::IdentifierBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/mapping/from_mods/identifier_builder.rb

Overview

Builds cocina identifier

Constant Summary collapse

ORCID_PREFIX =
'https://orcid.org/'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier_element:, type:) ⇒ IdentifierBuilder

Returns a new instance of IdentifierBuilder.



29
30
31
32
33
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 29

def initialize(identifier_element:, type:)
  @identifier_element = identifier_element
  @with_note = with_note
  @cocina_type, @mods_type, = types_for(type)
end

Class Method Details

.build_from_identifier(identifier_element:) ⇒ Hash

Returns a hash that can be mapped to a cocina model.

Parameters:

  • identifier_element (Nokogiri::XML::Element)

    identifier element

Returns:

  • (Hash)

    a hash that can be mapped to a cocina model



13
14
15
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 13

def self.build_from_identifier(identifier_element:)
  new(identifier_element: identifier_element, type: identifier_element[:type]).build
end

.build_from_name_identifier(identifier_element:) ⇒ Hash

Returns a hash that can be mapped to a cocina model.

Parameters:

  • identifier_element (Nokogiri::XML::Element)

    nameIdentifier element

Returns:

  • (Hash)

    a hash that can be mapped to a cocina model



25
26
27
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 25

def self.build_from_name_identifier(identifier_element:)
  new(identifier_element: identifier_element, type: identifier_element[:type]).build
end

.build_from_record_identifier(identifier_element:) ⇒ Hash

Returns a hash that can be mapped to a cocina model.

Parameters:

  • identifier_element (Nokogiri::XML::Element)

    recordIdentifier element

Returns:

  • (Hash)

    a hash that can be mapped to a cocina model



19
20
21
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 19

def self.build_from_record_identifier(identifier_element:)
  new(identifier_element: identifier_element, type: identifier_element[:source]).build
end

Instance Method Details

#buildObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 35

def build
  return if identifier_element.text.blank? && identifier_element.attributes.empty?

  {
    displayLabel: identifier_element['displayLabel']
  }.tap do |attrs|
    if cocina_type == 'uri'
      attrs[:uri] = identifier_element.text
    else
      attrs[:type] = cocina_type
      attrs[:value] = value
      attrs[:source] = build_source
    end
    attrs[:status] = 'invalid' if identifier_element['invalid'] == 'yes'
  end.compact
end