Sha256: 6224b686ab313d7496849ad0d6ee776f68ee05dfc4a408e08d9421deadc23a71

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

module Geoblacklight
  # Extends Blacklight::Solr::Document for GeoBlacklight specific functionalit
  module SolrDocument
    extend Blacklight::Solr::Document

    delegate :download_types, to: :references
    delegate :viewer_protocol, to: :item_viewer
    delegate :viewer_endpoint, to: :item_viewer

    def available?
      public? || same_institution?
    end

    def public?
      get(:dc_rights_s).downcase == 'public'
    end

    def restricted?
      get(:dc_rights_s).downcase == 'restricted'
    end

    def downloadable?
      (direct_download || download_types.present?) && available?
    end

    def download_types
      references.download_types
    end

    def references
      References.new(self)
    end

    def direct_download
      return references.download.to_hash unless references.download.blank?
    end

    def hgl_download
      return references.hgl.to_hash unless references.hgl.blank?
    end

    def same_institution?
      get(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
    end

    def item_viewer
      ItemViewer.new(references)
    end

    def itemtype
      "http://schema.org/Dataset"
    end

    ##
    # Provides a convenience method to access a SolrDocument's References
    # endpoint url without having to check and see if it is available
    # :type => a string which if its a Geoblacklight::Constants::URI key
    #          will return a coresponding Geoblacklight::Reference
    def checked_endpoint(type)
      type = references.send(type)
      type.endpoint if type.present?
    end

    private

    def method_missing(method, *args, &block)
      if /.*_url$/ =~ method.to_s
        checked_endpoint(method.to_s.gsub('_url', ''))
      else
        super
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
geoblacklight-0.6.2 lib/geoblacklight/solr_document.rb
geoblacklight-0.6.1 lib/geoblacklight/solr_document.rb
geoblacklight-0.6.0 lib/geoblacklight/solr_document.rb
geoblacklight-0.5.1 lib/geoblacklight/solr_document.rb
geoblacklight-0.5.0 lib/geoblacklight/solr_document.rb
geoblacklight-0.4.2 lib/geoblacklight/solr_document.rb
geoblacklight-0.4.1 lib/geoblacklight/solr_document.rb
geoblacklight-0.4.0 lib/geoblacklight/solr_document.rb