Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/mongoid_location/location/core_ext.rb
Instance Method Summary collapse
- #to_x ⇒ Object
- #to_xy ⇒ Object (also: #to_lng_lat)
- #to_y ⇒ Object
Instance Method Details
#to_x ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mongoid_location/location/core_ext.rb', line 23 def to_x v = (Mongoid::Location.lng_symbols & self.keys).first return self[v].to_f if !v.nil? && self[v] raise "Hash cannot contain #{Mongoid::Location.lat_symbols.inspect} as the first item if there is no #{Mongoid::Location.lng_symbols.inspect}" if Mongoid::Location.lat_symbols.index(self.keys[0]) self.values[0].to_f end |
#to_xy ⇒ Object Also known as: to_lng_lat
9 10 11 12 |
# File 'lib/mongoid_location/location/core_ext.rb', line 9 def to_xy raise "Hash must have at least 2 items" if self.size < 2 [to_x, to_y] end |
#to_y ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/mongoid_location/location/core_ext.rb', line 15 def to_y v = (Mongoid::Location.lat_symbols & self.keys).first return self[v].to_f if !v.nil? && self[v] raise "Hash must contain #{Mongoid::Location.lat_symbols.inspect} if ruby version is less than 1.9" if RUBY_VERSION.to_f < 1.9 raise "Hash cannot contain #{Mongoid::Location.lng_symbols.inspect} as the second item if there is no #{Mongoid::Location.lat_symbols.inspect}" if Mongoid::Location.lng_symbols.index(self.keys[1]) self.values[1].to_f end |