Class: GeoDistance::DistanceFormula
- Inherits:
-
Object
- Object
- GeoDistance::DistanceFormula
- Extended by:
- GeoUnits, Math
- Defined in:
- lib/geo-distance/formula.rb
Class Method Summary collapse
-
.geo_distance(*args) ⇒ Object
use underlying distance formula.
-
.get_points(*args) ⇒ Object
used to convert various argument types into GeoPoints.
-
.get_units(options = {}) ⇒ Object
used to get the units for how to calculate the distance.
Instance Method Summary collapse
-
#initialize ⇒ DistanceFormula
constructor
A new instance of DistanceFormula.
Constructor Details
#initialize ⇒ DistanceFormula
Returns a new instance of DistanceFormula.
8 9 10 |
# File 'lib/geo-distance/formula.rb', line 8 def initialize raise NotImplementedError end |
Class Method Details
.geo_distance(*args) ⇒ Object
use underlying distance formula
13 14 15 |
# File 'lib/geo-distance/formula.rb', line 13 def self.geo_distance *args GeoDistance.new distance(args), get_units(args.last_option) end |
.get_points(*args) ⇒ Object
used to convert various argument types into GeoPoints
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/geo-distance/formula.rb', line 18 def self.get_points(*args) args.flatten! = args.delete(args.last_option) || {} units = [:units] || GeoDistance.default_units case args.size when 2 [GeoPoint.new(args.first), GeoPoint.new(args.last), units] when 4 [GeoPoint.new(args[0..1]), GeoPoint.new(args[2..3]), units] else raise "Distance from point A to B, must be given either as 4 arguments (lat1, lng1, lat2, lng2) or 2 arguments: (pointA, pointB), was: #{args}" end end |
.get_units(options = {}) ⇒ Object
used to get the units for how to calculate the distance
34 35 36 |
# File 'lib/geo-distance/formula.rb', line 34 def self.get_units = {} GeoUnits.key([:units] || :kms) end |