Class: Geolocutor
Overview
Wrap Geocoder gem to calculate relative distances
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
readonly
Returns the value of attribute coordinates.
Instance Method Summary collapse
- #distance_from_here(there) ⇒ Object
-
#initialize(location, metric = false) ⇒ Geolocutor
constructor
A new instance of Geolocutor.
Constructor Details
#initialize(location, metric = false) ⇒ Geolocutor
Returns a new instance of Geolocutor.
10 11 12 13 |
# File 'lib/geolocutor.rb', line 10 def initialize(location, metric = false) @coordinates = coordinatize(location) @metric = metric end |
Instance Attribute Details
#coordinates ⇒ Object (readonly)
Returns the value of attribute coordinates.
8 9 10 |
# File 'lib/geolocutor.rb', line 8 def coordinates @coordinates end |
Instance Method Details
#distance_from_here(there) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/geolocutor.rb', line 15 def distance_from_here(there) there = coordinatize(extract_coordinates(there)) distance = Geocoder::Calculations.distance_between(@coordinates, there) return Geocoder::Calculations.to_kilometers(distance) if @metric Geocoder::Calculations.to_miles(distance) end |