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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier_element:, type:) ⇒ IdentifierBuilder

Returns a new instance of IdentifierBuilder.



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

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



11
12
13
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 11

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



23
24
25
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 23

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



17
18
19
# File 'lib/cocina/models/mapping/from_mods/identifier_builder.rb', line 17

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

Instance Method Details

#buildObject



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

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] = identifier_element.text
      attrs[:source] = build_source
    end
    attrs[:status] = 'invalid' if identifier_element['invalid'] == 'yes'
  end.compact
end