Class: ReverseGeocode

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

Defined Under Namespace

Classes: GeocodeError

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat, long) ⇒ ReverseGeocode

Returns a new instance of ReverseGeocode.

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/reverse_geocode.rb', line 26

def initialize(lat, long)
  raise ArgumentError, "Latitude and longitude required" unless lat && long
  @lat, @long = lat, long
end

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/reverse_geocode.rb', line 23

def api_key
  @api_key
end

Instance Attribute Details

#latObject (readonly)

Returns the value of attribute lat.



25
26
27
# File 'lib/reverse_geocode.rb', line 25

def lat
  @lat
end

#longObject (readonly)

Returns the value of attribute long.



25
26
27
# File 'lib/reverse_geocode.rb', line 25

def long
  @long
end

Instance Method Details

#addressObject



35
36
37
# File 'lib/reverse_geocode.rb', line 35

def address
  @address ||= first_placemark/'address'
end

#cityObject



51
52
53
# File 'lib/reverse_geocode.rb', line 51

def city
  @city ||= placemark[1]/'AddressDetails'/'Country'/'AdministrativeArea'/'Locality'/'LocalityName'
end

#countyObject



55
56
57
# File 'lib/reverse_geocode.rb', line 55

def county
  @county ||= (placemark[3]/'AddressDetails'/'Country'/'AdministrativeArea'/'AddressLine').first
end

#responseObject



31
32
33
# File 'lib/reverse_geocode.rb', line 31

def response
  @response ||= handle_response
end

#stateObject



43
44
45
# File 'lib/reverse_geocode.rb', line 43

def state
  @state ||= first_administrative_area/'AdministrativeAreaName'
end

#streetObject



39
40
41
# File 'lib/reverse_geocode.rb', line 39

def street
  @street ||= first_administrative_area/'Thoroughfare'/'ThoroughfareName'
end

#zipObject



47
48
49
# File 'lib/reverse_geocode.rb', line 47

def zip
  @zip ||= first_administrative_area/'PostalCode'/'PostalCodeNumber'
end