Sha256: 3150103ba0939c994ecc964b2843b2325d36308082715d7437ab8c4f1d05e445

Contents?: true

Size: 816 Bytes

Versions: 87

Compression:

Stored size: 816 Bytes

Contents

module ActiveFedora::Associations
  ##
  # A composite object for an array of IDs. This abstracts away the fact that an
  # ID might be either a relative ID or a URI to a resource.
  class IDComposite
    attr_reader :ids, :id_translator
    include Enumerable
    # @param [Array<#to_s>] ids An array of ids or URIs to convert to IDs.
    # @param [#call] id_translator An object to handle the conversion of a URI
    #   to an ID.
    def initialize(ids, id_translator)
      @ids = ids
      @id_translator = id_translator
    end

    # @return [Array<relative_id>]
    def each
      ids.each do |id|
        yield convert(id)
      end
    end

    private

      def convert(id)
        if id.to_s.start_with?("http")
          id_translator.call(id)
        else
          id
        end
      end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
active-fedora-15.0.1 lib/active_fedora/associations/id_composite.rb
active-fedora-15.0.0 lib/active_fedora/associations/id_composite.rb
active-fedora-14.0.1 lib/active_fedora/associations/id_composite.rb
active-fedora-14.0.0 lib/active_fedora/associations/id_composite.rb
active-fedora-13.3.0 lib/active_fedora/associations/id_composite.rb
active-fedora-12.2.4 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.7 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.5 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.4 lib/active_fedora/associations/id_composite.rb
active-fedora-12.2.3 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.3 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.2 lib/active_fedora/associations/id_composite.rb
active-fedora-13.2.0 lib/active_fedora/associations/id_composite.rb
active-fedora-13.1.3 lib/active_fedora/associations/id_composite.rb
active-fedora-11.5.6 lib/active_fedora/associations/id_composite.rb
active-fedora-12.2.2 lib/active_fedora/associations/id_composite.rb
active-fedora-11.2.1 lib/active_fedora/associations/id_composite.rb
active-fedora-12.2.1 lib/active_fedora/associations/id_composite.rb
active-fedora-12.0.3 lib/active_fedora/associations/id_composite.rb
active-fedora-11.5.5 lib/active_fedora/associations/id_composite.rb