Class: Mongoid::Geo::Unit
- Inherits:
-
Object
- Object
- Mongoid::Geo::Unit
- Defined in:
- lib/mongoid/geo/unit.rb
Class Method Summary collapse
- .distMultiplier(unit = :km) ⇒ Object
- .key(unit = :km) ⇒ Object
- .meters_map ⇒ Object
- .precision ⇒ Object
-
.radian_multiplier ⇒ Object
from mongoid-geo, as suggested by niedhui :).
- .unit_multiplier ⇒ Object
Class Method Details
.distMultiplier(unit = :km) ⇒ Object
13 14 15 16 17 |
# File 'lib/mongoid/geo/unit.rb', line 13 def distMultiplier unit = :km unit_key = key(unit) return radian_multiplier[unit_key] if unit_key && Mongoid::Geo.mongo_db_version >= 1.7 unit_multiplier[unit_key] if unit_key end |
.key(unit = :km) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/mongoid/geo/unit.rb', line 5 def key unit = :km unit = unit.to_sym methods.grep(/_unit/).each do |meth| return meth.to_s.chomp('_unit').to_sym if send(meth).include? unit end raise ArgumentError, "Unknown unit key: #{unit}" end |
.meters_map ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/mongoid/geo/unit.rb', line 49 def meters_map { :feet => 3.2808, :meters => 1, :kms => 0.001, :miles => 0.00062137, :radians => 111170 } end |
.precision ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoid/geo/unit.rb', line 19 def precision { :feet => 0, :meters => 2, :kms => 4, :miles => 4, :radians => 4 } end |
.radian_multiplier ⇒ Object
from mongoid-geo, as suggested by niedhui :)
30 31 32 33 34 35 36 37 38 |
# File 'lib/mongoid/geo/unit.rb', line 30 def radian_multiplier { :feet => 364491.8, :meters => 111170, :kms => 111.17, :miles => 69.407, :radians => 1 } end |
.unit_multiplier ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/mongoid/geo/unit.rb', line 40 def unit_multiplier { :feet => 0.305, :meters => 1, :kms => 6371, :miles => 3959 } end |