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

Returns:

  • (String)

    accuracy

See Also:

  • #accuracy_map


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

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

#addressString

Address

Returns:

  • (String)

    address



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

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

#cityString

City

Returns:

  • (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]

Returns:

  • (<Array>)

    lat, lng, elevation



134
135
136
# File 'lib/geocoder/response.rb', line 134

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

#countryString

Country

Returns:

  • (String)

    country



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

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

#elevationFloat

Elevation

Returns:

  • (Float)

    elevation



158
159
160
# File 'lib/geocoder/response.rb', line 158

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

#latFloat

Lat

Returns:

  • (Float)

    latitude



142
143
144
# File 'lib/geocoder/response.rb', line 142

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

#lngFloat

Lng

Returns:

  • (Float)

    longitude



150
151
152
# File 'lib/geocoder/response.rb', line 150

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

#stateString

State

Returns:

  • (String)

    state



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

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

#streetString

Street

Returns:

  • (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

#zipcodeString

Zipcode

Returns:

  • (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