Class: Geocoder::Address
- Inherits:
-
Object
- Object
- Geocoder::Address
- Defined in:
- lib/geocoder/response.rb
Instance Method Summary collapse
-
#accuracy ⇒ String
Accuracy.
-
#address ⇒ String
Address.
-
#city ⇒ String
City.
-
#coordinates ⇒ <Array>
Coordinates.
-
#country ⇒ String
Country.
-
#elevation ⇒ Float
Elevation.
-
#initialize(hash) ⇒ Address
constructor
Initialize class.
-
#lat ⇒ Float
Lat.
-
#lng ⇒ Float
Lng.
-
#state ⇒ String
State.
-
#street ⇒ String
Street.
-
#zipcode ⇒ String
Zipcode.
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
#accuracy ⇒ String
Accuracy
Convert Googles Accuracy integer into a word describing how accurate the match is
123 124 125 126 |
# File 'lib/geocoder/response.rb', line 123 def accuracy @accuracy ||= accuracy_map[@hash["AddressDetails"]["Accuracy"].to_i]\ rescue nil end |
#address ⇒ String
Address
66 67 68 |
# File 'lib/geocoder/response.rb', line 66 def address @address ||= @hash["address"] end |
#city ⇒ String
City
83 84 85 86 |
# File 'lib/geocoder/response.rb', line 83 def city @city ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\ ["Locality"]["LocalityName"] rescue nil end |
#coordinates ⇒ <Array>
Coordinates
An array of coordinates in the form of [lat, lng, elevation]
134 135 136 |
# File 'lib/geocoder/response.rb', line 134 def coordinates @coordinates ||= [lat, lng, elevation] end |
#country ⇒ String
Country
110 111 112 113 |
# File 'lib/geocoder/response.rb', line 110 def country @country ||= @hash["AddressDetails"]["Country"]["CountryNameCode"]\ rescue nil end |
#elevation ⇒ Float
Elevation
158 159 160 |
# File 'lib/geocoder/response.rb', line 158 def elevation @elevation ||= @hash["Point"]["coordinates"][2].to_f rescue nil end |
#lat ⇒ Float
Lat
142 143 144 |
# File 'lib/geocoder/response.rb', line 142 def lat @lat ||= @hash["Point"]["coordinates"][0].to_f rescue nil end |
#lng ⇒ Float
Lng
150 151 152 |
# File 'lib/geocoder/response.rb', line 150 def lng @lng ||= @hash["Point"]["coordinates"][1].to_f rescue nil end |
#state ⇒ String
State
92 93 94 95 |
# File 'lib/geocoder/response.rb', line 92 def state @state ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\ ["AdministrativeAreaName"] rescue nil end |
#street ⇒ String
Street
74 75 76 77 |
# File 'lib/geocoder/response.rb', line 74 def street @street ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\ ["Locality"]["Thoroughfare"]["ThoroughfareName"] rescue nil end |
#zipcode ⇒ String
Zipcode
101 102 103 104 |
# File 'lib/geocoder/response.rb', line 101 def zipcode @zipcode ||= @hash["AddressDetails"]["Country"]["AdministrativeArea"]\ ["Locality"]["PostalCode"]["PostalCodeNumber"] rescue nil end |