Sha256: 567b592d5d2f49ded26667a4714ee47ca8ff1d55e43aa1b49b9931cdd3574d0b

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

module Hydra::Works
  # This module provides all of the Behaviors of a Hydra::Works::Collection
  #
  # behavior:
  #   1) Hydra::Works::Collection can aggregate Hydra::Works::Collection
  #   2) Hydra::Works::Collection can aggregate Hydra::Works::Work

  #   3) Hydra::Works::Collection can NOT aggregate Hydra::PCDM::Collection unless it is also a Hydra::Works::Collection
  #   4) Hydra::Works::Collection can NOT aggregate Hydra::Works::FileSet
  #   5) Hydra::Works::Collection can NOT aggregate non-PCDM object
  #   6) Hydra::Works::Collection can NOT contain Hydra::PCDM::File
  #   7) Hydra::Works::Collection can NOT contain

  #   8) Hydra::Works::Collection can have descriptive metadata
  #   9) Hydra::Works::Collection can have access metadata
  module CollectionBehavior
    extend ActiveSupport::Concern

    included do
      def self.type_validator
        Hydra::PCDM::Validators::CompositeValidator.new(
          super,
          Hydra::Works::NotFileSetValidator
        )
      end
      include Hydra::PCDM::CollectionBehavior

      type [Hydra::PCDM::Vocab::PCDMTerms.Collection, Vocab::WorksTerms.Collection]
    end

    def ordered_works
      ordered_members.to_a.select(&:work?)
    end

    def ordered_work_ids
      ordered_works.map(&:id)
    end

    def works
      members.select(&:work?)
    end

    def work_ids
      works.map(&:id)
    end

    # @return [Boolean] whether this instance is a Hydra::Works Collection.
    def collection?
      true
    end

    # @return [Boolean] whether this instance is a Hydra::Works Generic Work.
    def work?
      false
    end

    # @return [Boolean] whether this instance is a Hydra::Works::FileSet.
    def file_set?
      false
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hydra-works-1.0.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.17.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.16.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.15.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.12.1 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.14.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.13.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.12.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.11.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.10.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.9.0 lib/hydra/works/models/concerns/collection_behavior.rb
hydra-works-0.8.1 lib/hydra/works/models/concerns/collection_behavior.rb