Class: Geoblacklight::References

Inherits:
Object
  • Object
show all
Defined in:
lib/geoblacklight/references.rb

Overview

References is a geoblacklight-schema dct:references parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ References

Returns a new instance of References.


5
6
7
8
# File 'lib/geoblacklight/references.rb', line 5

def initialize(document)
  @document = document
  @refs = parse_references.map { |ref| Reference.new(ref) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &b) ⇒ Object


10
11
12
13
14
15
16
# File 'lib/geoblacklight/references.rb', line 10

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

Instance Attribute Details

#refsObject (readonly)

Returns the value of attribute refs


4
5
6
# File 'lib/geoblacklight/references.rb', line 4

def refs
  @refs
end

Instance Method Details

#download_typesObject


55
56
57
# File 'lib/geoblacklight/references.rb', line 55

def download_types
  downloads_by_format
end

#downloads_by_formatObject


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/geoblacklight/references.rb', line 42

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

#file_downloadObject


38
39
40
# File 'lib/geoblacklight/references.rb', line 38

def file_download
  { file_download: download.to_hash }
end

#formatObject


18
19
20
# File 'lib/geoblacklight/references.rb', line 18

def format
  @document[:dc_format_s]
end

#parse_referencesObject


26
27
28
29
30
31
32
# File 'lib/geoblacklight/references.rb', line 26

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

#preferred_downloadObject


34
35
36
# File 'lib/geoblacklight/references.rb', line 34

def preferred_download
  return file_download unless download.blank?
end

#references(ref_type) ⇒ Object


22
23
24
# File 'lib/geoblacklight/references.rb', line 22

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