Sha256: 9c4aa7b8a545e7f7ab6de29819b7f8faccd49ff53b5cdc6450888fb7dcc81d20
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
module Mongoid module Geospatial def self.from_array(ary) ary[0..1].map(&:to_f) end def self.from_hash(hsh) fail 'Hash must have at least 2 items' if hsh.size < 2 [from_hash_x(hsh), from_hash_y(hsh)] end def self.from_hash_y(hsh) v = (Mongoid::Geospatial.lat_symbols & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] fail "Hash must contain #{Mongoid::Geospatial.lat_symbols.inspect} if ruby version is less than 1.9" if RUBY_VERSION.to_f < 1.9 fail "Hash cannot contain #{Mongoid::Geospatial.lng_symbols.inspect} as the second item if there is no #{Mongoid::Geospatial.lat_symbols.inspect}" if Mongoid::Geospatial.lng_symbols.index(hsh.keys[1]) hsh.values[1].to_f end def self.from_hash_x(hsh) v = (Mongoid::Geospatial.lng_symbols & hsh.keys).first return hsh[v].to_f if !v.nil? && hsh[v] fail "Hash cannot contain #{Mongoid::Geospatial.lat_symbols.inspect} as the first item if there is no #{Mongoid::Geospatial.lng_symbols.inspect}" if Mongoid::Geospatial.lat_symbols.index(keys[0]) values[0].to_f end end end
Version data entries
3 entries across 3 versions & 1 rubygems