Sha256: 7a6eca0575863e008e3a6ac4bcb27884d945ad4e88d23b6c9399e185868a79da

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module Geoblacklight
  # References is a geoblacklight-schema dct:references parser
  class References
    attr_reader :refs
    def initialize(document)
      @document = document
      @refs = parse_references.map { |ref| Reference.new(ref) }
    end

    def method_missing(m, *args, &b)
      if Geoblacklight::Constants::URI.key?(m)
        references m
      else
        super
      end
    end

    def format
      @document[:dc_format_s]
    end

    def references(ref_type)
      @refs.find { |reference| reference.type == ref_type }
    end

    def parse_references
      if @document[:dct_references_s].nil?
        Hash.new
      else
        JSON.parse(@document[:dct_references_s])
      end
    end

    def preferred_download
      return file_download unless download.blank?
    end

    def file_download
      { file_download: download.to_hash }
    end

    def downloads_by_format
      case format
      when 'Shapefile'
        { shapefile: wfs.to_hash, kmz: wms.to_hash, geojson: wfs.to_hash }
      when 'GeoTIFF'
        { geotiff: wms.to_hash } if wms.present?
      end
    end

    def download_types
      downloads_by_format
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geoblacklight-0.2.1 lib/geoblacklight/references.rb
geoblacklight-0.2.0 lib/geoblacklight/references.rb