lib/geo_units.rb in geo_units-0.3.3 vs lib/geo_units.rb in geo_units-0.3.4

- old
+ new

@@ -1,22 +1,23 @@ - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Geodesy representation conversion functions (c) Chris Veness 2002-2010 # - www.movable-type.co.uk/scripts/latlong.html # - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Parses string representing degrees/minutes/seconds into numeric degrees -# +# # This is very flexible on formats, allowing signed decimal degrees, or deg-min-sec optionally -# suffixed by compass direction (NSEW). A variety of separators are accepted (eg 3º 37' 09"W) -# or fixed-width format without separators (eg 0033709W). Seconds and minutes may be omitted. +# suffixed by compass direction (NSEW). A variety of separators are accepted (eg 3º 37' 09"W) +# or fixed-width format without separators (eg 0033709W). Seconds and minutes may be omitted. # (Note minimal validation is done). -# +# # @param [String|Number] Degrees or deg/min/sec in variety of formats # @returns [Number] Degrees as decimal number # @throws ArgumentError +require 'active_support' require 'sugar-high/numeric' require 'sweetloader' module GeoUnits autoload_modules :Constants, :Converter, :Maps, :Numeric @@ -28,11 +29,11 @@ @default_coords_order ||= :lng_lat end end def self.included(base) - [:Maps, :Constants, :"Converter::Units"].each do |module_name| + [:Maps, :Constants, :"Converter::Units"].each do |module_name| module_name = "GeoUnits::#{module_name.to_s.camelize}".constantize base.send :include, module_name base.extend module_name end end @@ -41,13 +42,13 @@ [:feet, :meters, :kms, :kilometers, :miles, :radians] end (units - [:radians]).each do |unit_type| define_singleton_method "#{unit_type}_to" do |unit, number = 0| - return 0 if number <= 0 + return 0 if number <= 0 unit = normalized(unit) - + converter = GeoUnits::Maps::Meters from = converter.from_unit[unit_type] to = converter.to_unit[unit] m = number * from * to @@ -56,10 +57,10 @@ def self.radians_to unit, number, lat = 0 unit = normalized(unit) # factor = GeoUnits::Converter::Units.units_per_longitude_degree(lat, unit) # puts "factor: #{factor} - #{unit}" - (GeoUnits::Maps::Earth.distance_per_latitude_degree[unit] * number.to_f) + (GeoUnits::Maps::Earth.distance_per_latitude_degree[unit] * number.to_f) end module ClassMethods def normalized unit = :km unit = key(unit)