class Array
Public Instance Methods
parse_dms(direction = nil)
click to toggle source
# File lib/geo_units/core_ext.rb, line 49 def parse_dms direction = nil lng, lat = extract_coords(direction) direction == :lat_lng ? [lat.parse_dms, lng.parse_dms] : [lng.parse_dms, lat.parse_dms] end
to_dms(direction = nil)
click to toggle source
# File lib/geo_units/core_ext.rb, line 43 def to_dms direction = nil lng, lat = extract_coords(direction) res = direction == :lat_lng ? [lat.to_lat_dms, lng.to_lng_dms] : [lng.to_lng_dms, lat.to_lat_dms] res.join(', ') end
Protected Instance Methods
extract_coords(direction = nil)
click to toggle source
# File lib/geo_units/core_ext.rb, line 56 def extract_coords direction = nil direction ||= GeoUnits.default_coords_order unless [:lng_lat, :lat_lng].include? direction raise ArgumentError, "Direction must be either :lng_lat or :lat_lng, was: #{direction}. You can also set the default direction via GeoUnits#default_direction=" end lat_index = direction == :reverse ? 0 : 1 lng_index = direction == :reverse ? 1 : 0 lat = self.to_lat if self.respond_to?(:to_lat) lat ||= self[lat_index] if self[lat_index].respond_to?(:to_lat) && self[lat_index].to_lat lat ||= self[lng_index] if self[lng_index].respond_to?(:to_lat) && self[lng_index].to_lat lat ||= self[lat_index] lng = self.to_lng if self.respond_to?(:to_lng) lng ||= self[lng_index] if self[lng_index].respond_to?(:to_lng) && self[lng_index].to_lng lng ||= self[lat_index] if self[lat_index].respond_to?(:to_lng) && self[lat_index].to_lng lng ||= self[lng_index] [lng, lat] end