class Geoblacklight::References

References is a geoblacklight-schema dct:references parser

Attributes

reference_field[R]
refs[R]

Public Class Methods

new(document, reference_field = Settings.FIELDS.REFERENCES) click to toggle source
# File lib/geoblacklight/references.rb, line 6
def initialize(document, reference_field = Settings.FIELDS.REFERENCES)
  @document = document
  @reference_field = reference_field
  @refs = parse_references.map { |ref| Reference.new(ref) }
end

Public Instance Methods

download_types() click to toggle source

Generated download types from wxs services @return (see downloads_by_format)

# File lib/geoblacklight/references.rb, line 67
def download_types
  downloads_by_format
end
downloads_by_format() click to toggle source

Download hash based off of format type @return [Hash, nil]

# File lib/geoblacklight/references.rb, line 53
def downloads_by_format
  case format
  when 'Shapefile'
    vector_download_formats
  when 'GeoTIFF'
    geotiff_download_formats
  when 'ArcGRID'
    arcgrid_download_formats
  end
end
esri_webservices() click to toggle source

Returns all of the Esri webservices for given set of references

# File lib/geoblacklight/references.rb, line 73
def esri_webservices
  %w[tiled_map_layer dynamic_map_layer feature_layer image_map_layer].map do |layer_type|
    send(layer_type)
  end.compact
end
format() click to toggle source

Accessor for a document's file format @return [String] file format for the document

# File lib/geoblacklight/references.rb, line 32
def format
  @document[Settings.FIELDS.FILE_FORMAT]
end
preferred_download() click to toggle source

Preferred download (should be a file download) @return [Hash, nil]

# File lib/geoblacklight/references.rb, line 46
def preferred_download
  return file_download if download.present?
end
references(ref_type) click to toggle source

@param [String, Symbol] ref_type @return [Geoblacklight::Reference]

# File lib/geoblacklight/references.rb, line 39
def references(ref_type)
  @refs.find { |reference| reference.type == ref_type }
end
shown_metadata() click to toggle source

Return only metadata for shown metadata @return [Geoblacklight::Metadata::Base]

# File lib/geoblacklight/references.rb, line 25
def shown_metadata
  @shown_metadata ||= shown_metadata_refs.map { |ref| Geoblacklight::Metadata.instance(ref) }
end
shown_metadata_refs() click to toggle source

Return only those metadata references which are exposed within the configuration @return [Geoblacklight::Reference]

# File lib/geoblacklight/references.rb, line 15
def shown_metadata_refs
  metadata = @refs.select { |ref| Settings.METADATA_SHOWN.include?(ref.type.to_s) }
  metadata.sort do |u, v|
    Settings.METADATA_SHOWN.index(u.type.to_s) <=> Settings.METADATA_SHOWN.index(v.type.to_s)
  end
end

Private Instance Methods

arcgrid_download_formats() click to toggle source

Download hash for an ArcGRID file with a WMS reference present @return (see downloads_by_format)

# File lib/geoblacklight/references.rb, line 122
def arcgrid_download_formats
  { geotiff: wms.to_hash } if wms.present?
end
file_download() click to toggle source

Download hash for a static file download @return (see downloads_by_format)

# File lib/geoblacklight/references.rb, line 95
def file_download
  { file_download: download.to_hash }
end
geotiff_download_formats() click to toggle source

Download hash for a GeoTiff file with a WMS reference present @return (see downloads_by_format)

# File lib/geoblacklight/references.rb, line 115
def geotiff_download_formats
  { geotiff: wms.to_hash } if wms.present?
end
method_missing(m, *args, &b) click to toggle source

Adds a call to references for defined URI keys

Calls superclass method
# File lib/geoblacklight/references.rb, line 128
def method_missing(m, *args, &b)
  if Geoblacklight::Constants::URI.key?(m)
    references m
  else
    super
  end
end
parse_references() click to toggle source

Parses the references field of a document @return [Hash]

# File lib/geoblacklight/references.rb, line 84
def parse_references
  if @document[reference_field].nil?
    {}
  else
    JSON.parse(@document[reference_field])
  end
end
vector_download_formats() click to toggle source

Download hash for a Shapefile file (currently only vector) with a wms and wfs reference present @return (see downloads_by_format)

# File lib/geoblacklight/references.rb, line 103
def vector_download_formats
  return unless wms.present? && wfs.present?
  {
    shapefile: wfs.to_hash,
    kmz: wms.to_hash,
    geojson: wfs.to_hash
  }
end