Sha256: b27dd5c0090810e1e570616e370190fb41ba97e59c6f0f4f82f6800869d265bd

Contents?: true

Size: 1.82 KB

Versions: 24

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.empty? }
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cocina-models-0.99.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.99.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.98.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.98.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.96.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.95.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.95.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.94.2 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.94.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.94.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.93.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.93.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.92.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.91.4 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.91.3 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.91.2 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.91.1 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.91.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.90.0 lib/cocina/models/mapping/from_mods/identifier.rb
cocina-models-0.89.1 lib/cocina/models/mapping/from_mods/identifier.rb