Class: Geocoder::Result::Opencagedata

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/opencagedata.rb

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Class Method Details

.response_attributesObject


69
70
71
72
# File 'lib/geocoder/results/opencagedata.rb', line 69

def self.response_attributes
  %w[boundingbox license 
    formatted stadium]
end

Instance Method Details

#addressObject


17
18
19
# File 'lib/geocoder/results/opencagedata.rb', line 17

def address
  @data['formatted']
end

#cityObject


28
29
30
31
32
33
# File 'lib/geocoder/results/opencagedata.rb', line 28

def city
  %w[city town village hamlet].each do |key|
    return @data['components'][key] if @data['components'].key?(key)
  end
  return nil
end

#coordinatesObject


66
67
68
# File 'lib/geocoder/results/opencagedata.rb', line 66

def coordinates
  [@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
end

#countryObject


54
55
56
# File 'lib/geocoder/results/opencagedata.rb', line 54

def country
  @data['components']['country']
end

#country_codeObject


58
59
60
# File 'lib/geocoder/results/opencagedata.rb', line 58

def country_code
  @data['components']['country_code']
end

#countyObject


50
51
52
# File 'lib/geocoder/results/opencagedata.rb', line 50

def county
  @data['components']['county']
end

#house_numberObject


13
14
15
# File 'lib/geocoder/results/opencagedata.rb', line 13

def house_number
  @data['components']['house_number']
end

#poiObject


6
7
8
9
10
11
# File 'lib/geocoder/results/opencagedata.rb', line 6

def poi
  %w[stadium bus_stop tram_stop].each do |key|
    return @data['components'][key] if @data['components'].key?(key)
  end
  return nil
end

#postal_codeObject


46
47
48
# File 'lib/geocoder/results/opencagedata.rb', line 46

def postal_code
  @data['components']['postcode'].to_s
end

#stateObject Also known as: state_code


40
41
42
# File 'lib/geocoder/results/opencagedata.rb', line 40

def state
  @data['components']['state']
end

#streetObject


21
22
23
24
25
26
# File 'lib/geocoder/results/opencagedata.rb', line 21

def street
  %w[road pedestrian highway].each do |key|
    return @data['components'][key] if @data['components'].key?(key)
  end
  return nil
end

#suburbObject


62
63
64
# File 'lib/geocoder/results/opencagedata.rb', line 62

def suburb
  @data['components']['suburb']
end

#villageObject


35
36
37
# File 'lib/geocoder/results/opencagedata.rb', line 35

def village
  @data['components']['village']
end