Sha256: 34d6f767c832e92dbcbc82bc0b6e127a7d3a1caad9ad721ac2ddd9755b862eb9
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
module Mongoid module Geospatial def self.from_array(ary) ary[0..1].map(&:to_f) end def self.from_hash(hsh) raise '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] if Mongoid::Geospatial.lng_symbols.index(hsh.keys[1]) raise "Hash cannot contain #{Mongoid::Geospatial.lng_symbols.inspect} "\ "as second arg without #{Mongoid::Geospatial.lat_symbols.inspect}" end 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] if Mongoid::Geospatial.lat_symbols.index(keys[0]) raise "Hash cannot contain #{Mongoid::Geospatial.lat_symbols.inspect} "\ "as first arg without #{Mongoid::Geospatial.lng_symbols.inspect}" end values[0].to_f end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid-geospatial-5.1.0 | spec/mongoid/geospatial/helpers/core_spec.rb |