Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_spacial/spacial/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_latObject



13
14
15
16
17
18
19
# File 'lib/mongoid_spacial/spacial/core_ext.rb', line 13

def to_lat
  v = (Mongoid::Spacial.lat_symbols & self.keys).first
  return self[v].to_f if !v.nil? && self[v]
  raise "Hash must contain #{Mongoid::Spacial.lat_symbols.inspect} if ruby version is less than 1.9" if RUBY_VERSION.to_f < 1.9
  raise "Hash cannot contain #{Mongoid::Spacial.lng_symbols.inspect} as the second item if there is no #{Mongoid::Spacial.lat_symbols.inspect}" if Mongoid::Spacial.lng_symbols.index(self.keys[1])
  self.values[1].to_f
end

#to_lngObject



21
22
23
24
25
26
# File 'lib/mongoid_spacial/spacial/core_ext.rb', line 21

def to_lng
  v = (Mongoid::Spacial.lng_symbols & self.keys).first
  return self[v].to_f if !v.nil? && self[v]
  raise "Hash cannot contain #{Mongoid::Spacial.lat_symbols.inspect} as the first item if there is no #{Mongoid::Spacial.lng_symbols.inspect}" if Mongoid::Spacial.lat_symbols.index(self.keys[0])
  self.values[0].to_f
end

#to_lng_latObject



8
9
10
11
# File 'lib/mongoid_spacial/spacial/core_ext.rb', line 8

def to_lng_lat
  raise "Hash must have at least 2 items" if self.size < 2
  [to_lng, to_lat]
end