Class: Geocoder::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/geocoder/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Address

Initialize class

set @hash to the json parsed hash



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

def initialize(hash)
  @hash = hash
end

Instance Method Details

#accuracyString

Accuracy

Convert Googles Accuracy integer into a word describing how accurate the match is

See Also:

  • #accuracy_map


122
123
124
# File 'lib/geocoder/response.rb', line 122

def accuracy
  @accuracy ||= accuracy_map[@hash["AddressDetails"]["Accuracy"].to_i]
end

#addressString

Address



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

def address
  @address ||= @hash["address"]
end

#cityString

City



83
84
85
86
# File 'lib/geocoder/response.rb', line 83

def city
 @city ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\
                ["Locality"]["LocalityName"]
end

#coordinates<Array>

Coordinates

An array of coordinates in the form of [lat, lng, elevation]



132
133
134
# File 'lib/geocoder/response.rb', line 132

def coordinates
  @coordinates ||= [lat, lng, elevation]
end

#countryString

Country



110
111
112
# File 'lib/geocoder/response.rb', line 110

def country
  @country ||= @hash["AddressDetails"]["Country"]["CountryNameCode"]
end

#elevationFloat

Elevation



156
157
158
# File 'lib/geocoder/response.rb', line 156

def elevation
  @elevation ||= @hash["Point"]["coordinates"][2].to_f
end

#latFloat

Lat



140
141
142
# File 'lib/geocoder/response.rb', line 140

def lat
  @lat ||= @hash["Point"]["coordinates"][0].to_f
end

#lngFloat

Lng



148
149
150
# File 'lib/geocoder/response.rb', line 148

def lng
  @lng ||= @hash["Point"]["coordinates"][1].to_f
end

#stateString

State



92
93
94
95
# File 'lib/geocoder/response.rb', line 92

def state
  @state ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\
                  ["AdministrativeAreaName"]
end

#streetString

Street



74
75
76
77
# File 'lib/geocoder/response.rb', line 74

def street
  @street ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\
                   ["Locality"]["Thoroughfare"]["ThoroughfareName"]
end

#zipcodeString

Zipcode



101
102
103
104
# File 'lib/geocoder/response.rb', line 101

def zipcode
  @zipcode ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\
                    ["Locality"]["PostalCode"]["PostalCodeNumber"]
end