Permalink
Browse files

unit class added to support multiple unit keys and formats

  • Loading branch information...
1 parent 0d0d635 commit 729577bc0704fa7ebac6b06c6fb7181bf881cf1e @kristianmandrup committed May 5, 2011
Showing with 41 additions and 3 deletions.
  1. +10 −3 lib/geo_magic/distance/conversion.rb
  2. +31 −0 lib/geo_magic/distance/unit.rb
@@ -109,10 +109,17 @@ def radian_multiplier
def meters_map
{
- :miles => 0.00062,
- :feet => 3.28,
+ :mil => 69.407,
+ :mile => 0.00062137,
+ :miles => 0.00062137,
+ :ft => 3.2808,
+ :feet => 3.2808,
:km => 0.001,
- :meters => 1
+ :kms => 0.001,
+ :kilometers => 0.001,
+ :m => 1,
+ :meter => 1,
+ :meters => 1
}
end
end
@@ -0,0 +1,31 @@
+module GeoMagic
+ class Unit
+ class << self
+
+ def key unit
+ methods.grep(/_unit/).each do |meth|
+ return meth.chomp('_unit').to_sym
+ end
+ end
+
+ protected
+
+ def feet_unit
+ [:ft, :feet, :foot]
+ end
+
+ def meter_unit
+ [:m, :meter, :meters]
+ end
+
+ def km_unit
+ [:km, :kms, :kilometer, :kilometers]
+ end
+
+ def mile_unit
+ [:mil, :mile, :miles]
+ end
+ end
+ end
+end
+

0 comments on commit 729577b

Please sign in to comment.