Sha256: 23d44e8e1fccea0f7cde5b16fb34567ee32124371cb385ef03d3a5b569de1c9b

Contents?: true

Size: 956 Bytes

Versions: 1

Compression:

Stored size: 956 Bytes

Contents

module Pupa
  module Concerns
    # Adds the Popolo `identifiers` property to a model.
    module Identifiable
      extend ActiveSupport::Concern

      included do
        attr_reader :identifiers
        dump :identifiers
      end

      def initialize(*args)
        @identifiers = IdentifierList.new
        super
      end

      # Sets the identifiers.
      #
      # @param [Array] identifiers a list of identifiers
      def identifiers=(identifiers)
        @identifiers = IdentifierList.new(identifiers)
      end

      # Adds an issued identifier.
      #
      # @param [String] identifier an issued identifier, e.g. a DUNS number
      # @param [String] scheme an identifier scheme, e.g. DUNS
      def add_identifier(identifier, scheme: nil)
        data = {identifier: identifier}
        if scheme
          data[:scheme] = scheme
        end
        if identifier
          @identifiers << data
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupa-0.0.10 lib/pupa/models/concerns/identifiable.rb