Skip to content
Snippets Groups Projects
Commit b082749e authored by Alex Reisner's avatar Alex Reisner
Browse files

Improve comments, rename 'assign_coordinates' method, add optional parameter...

Improve comments, rename 'assign_coordinates' method, add optional parameter to fetch_coordinates for query term method name.
parent c0c9bf34
No related branches found
No related tags found
No related merge requests found
##
# Add geocoding functionality (via Google) to any object that implements
# a +location+ method that returns a string suitable for a Google Maps search.
# a method (+location+ by default) that returns a string suitable for a
# Google Maps search. The object should also implement reader and writer
# methods for +latitude+ and +longitude+ attributes.
#
module Geocoder
......@@ -24,15 +26,15 @@ module Geocoder
##
# Search Google based on the object's +location+ attribute.
#
def fetch_coordinates
Geocoder.fetch_coordinates(location)
def fetch_coordinates(attribute = :location)
Geocoder.fetch_coordinates(send(attribute))
end
##
# Fetch and assign +latitude+ and +longitude+ if +location+ has changed.
# Fetch and assign +latitude+ and +longitude+.
#
def assign_coordinates
if location_changed? and c = fetch_coordinates
def fetch_and_assign_coordinates(attribute = :location)
if c = fetch_coordinates(attribute)
self.latitude = c[0]
self.longitude = c[1]
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment