Class: Geolocutor

Inherits:
Object
  • Object
show all
Includes:
Geocoder
Defined in:
lib/geolocutor.rb

Overview

Wrap Geocoder gem to calculate relative distances

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#coordinatesObject (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