Class: Geoblacklight::FeatureInfoResponse

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

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ FeatureInfoResponse

Returns a new instance of FeatureInfoResponse.



5
6
7
# File 'lib/geoblacklight/wms_layer/feature_info_response.rb', line 5

def initialize(response)
  @response = response
end

Instance Method Details

#checkObject



9
10
11
12
13
14
15
# File 'lib/geoblacklight/wms_layer/feature_info_response.rb', line 9

def check
  if error?
    @response
  else
    format
  end
end

#error?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/geoblacklight/wms_layer/feature_info_response.rb', line 32

def error?
  @response[:error] ||
    @response.headers["content-type"].slice(0, 9) == "text/xml"
end

#formatObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/geoblacklight/wms_layer/feature_info_response.rb', line 17

def format
  JSON.parse(@response.body)
rescue
  page = Nokogiri::HTML(@response.body)
  properties = {}
  values = {}
  page.css("td").each_with_index do |td, index|
    values[index] = td.text
  end
  page.css("th").each_with_index do |th, index|
    properties[th.text] = values[index] unless index >= values.keys.count
  end
  {features: [{properties: properties, isHTML: true}]}
end