Sha256: a0c37f5ee5a9f32240a9e30e22576ffd992b00948c31cb93da1f4e051f60095e

Contents?: true

Size: 1.82 KB

Versions: 16

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module Cocina
  module Models
    module Mapping
      module FromMods
        # Maps MODS identifer to cocina identifier
        class Identifier
          # @param [Nokogiri::XML::Element] resource_element mods or relatedItem element
          # @param [Cocina::Models::Mapping::FromMods::DescriptionBuilder] description_builder
          # @param [String] purl
          # @return [Hash] a hash that can be mapped to a cocina model
          def self.build(resource_element:, description_builder: nil, purl: nil)
            new(resource_element: resource_element).build
          end

          def initialize(resource_element:)
            @resource_element = resource_element
          end

          def build
            altrepgroup_identifier_nodes, other_identifier_nodes = AltRepGroup.split(nodes: identifiers)

            altrepgroup_identifier_nodes.map { |id_nodes| build_parallel(id_nodes) } +
              other_identifier_nodes.map do |id_node|
                IdentifierBuilder.build_from_identifier(identifier_element: id_node)
              end
          end

          private

          attr_reader :resource_element

          def build_parallel(identifier_nodes)
            {
              parallelValue: identifier_nodes.map do |id_node|
                               IdentifierBuilder.build_from_identifier(identifier_element: id_node)
                             end
            }
          end

          def identifiers
            (resource_element.xpath('mods:identifier', mods: Description::DESC_METADATA_NS) +
              resource_element.xpath('mods:recordIdentifier',
                                     mods: Description::DESC_METADATA_NS)).reject { |identifier_node| identifier_node.text.blank? && identifier_node.attributes.size.zero? }
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
cocina-models-0.86.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.85.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.5 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.4 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.3 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.2 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.84.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.83.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.82.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.81.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.80.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.79.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.78.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.77.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.76.0 lib/cocina/models/mapping/from_mods/identifier.rb