Sha256: 17e32a22b1c77b0eaaa971d16d8a045f9dc39f5370f519d397b4ee8e32e6c2ae

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

module GeoWorks
  # Attributes and methods for vector works
  module VectorWorkBehavior
    extend ActiveSupport::Concern
    include ::GeoWorks::MetadataExtractionHelper

    included do
      type [Hydra::PCDM::Vocab::PCDMTerms.Object,
            Hydra::Works::Vocab::WorksTerms.GenericWork,
            ::GeoWorks::GeoTerms.VectorWork]
    end

    def vector_files
      members.select(&:vector_file?)
    end

    def metadata_files
      members.select(&:external_metadata_file?)
    end

    # Defines type by what it is and isn't
    # @return [Boolean]
    def image_work?
      false
    end

    def image_file?
      false
    end

    def raster_work?
      false
    end

    def raster_file?
      false
    end

    def vector_work?
      true
    end

    def vector_file?
      false
    end

    def external_metadata_file?
      false
    end

    # Retrieve all Raster Works for which this Vector Work can be extracted
    # @return [Array]
    def raster_works
      ordered_by.select do |parent|
        parent.class.included_modules.include?(::GeoWorks::RasterWorkBehavior)
      end
    end

    # Retrieve the only Raster Work for which feature extraction generates this Vector Work
    # @return [GeoWorks::RasterWork]
    def raster_work
      raster_works.first
    end

    def to_solr(solr_doc = {})
      super.tap do |doc|
        doc[solr_name("ordered_by", :symbol)] ||= []
        doc[solr_name("ordered_by", :symbol)] += send(:ordered_by_ids)
      end
    end

    private

      def solr_name(*args)
        ActiveFedora.index_field_mapper.solr_name(*args)
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geo_works-0.2.0 app/models/concerns/geo_works/vector_work_behavior.rb
geo_works-0.1.4 app/models/concerns/geo_works/vector_work_behavior.rb
geo_works-0.1.3 app/models/concerns/geo_works/vector_work_behavior.rb
geo_works-0.1.2 app/models/concerns/geo_works/vector_work_behavior.rb
geo_works-0.1.1 app/models/concerns/geo_works/vector_work_behavior.rb
geo_works-0.1.0 app/models/concerns/geo_works/vector_work_behavior.rb