Class: ReverseGeocode

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

Defined Under Namespace

Classes: GeocodeError

Constant Summary collapse

GOOGLE_URI =
"http://maps.google.com/maps/geo"

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)


28
29
30
31
# File 'lib/reverse_geocode.rb', line 28

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.



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

def api_key
  @api_key
end

Instance Attribute Details

#latObject (readonly)

Returns the value of attribute lat.



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

def lat
  @lat
end

#longObject (readonly)

Returns the value of attribute long.



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

def long
  @long
end

Instance Method Details

#addressObject



37
38
39
# File 'lib/reverse_geocode.rb', line 37

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

#cityObject



53
54
55
# File 'lib/reverse_geocode.rb', line 53

def city
  @city ||= (placemark_by_accuracy(4)/'AddressDetails'/'Country'/'AdministrativeArea'/'AddressLine').first
end

#countyObject



57
58
59
# File 'lib/reverse_geocode.rb', line 57

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

#responseObject



33
34
35
# File 'lib/reverse_geocode.rb', line 33

def response
  @response ||= handle_response
end

#stateObject



45
46
47
# File 'lib/reverse_geocode.rb', line 45

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

#streetObject



41
42
43
# File 'lib/reverse_geocode.rb', line 41

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

#zipObject



49
50
51
# File 'lib/reverse_geocode.rb', line 49

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