Module: Mongoid::Geo::Point

Defined in:
lib/mongoid/geo/point.rb

Instance Method Summary collapse

Instance Method Details

#to_pointObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mongoid/geo/point.rb', line 9

def to_point
  case self
  when Hash
    return [self[:lat], self[:lng]] if self[:lat]
    return [self[:latitude], self[:longitude]] if self[:latitude]
    raise "Hash must contain either :lat, :lng or :latitude, :longitude keys to be converted to a geo point"
  when nil
    nil
  when Array
    self.map(&:to_f)
  else
    obj   = self.send(:location) if respond_to? :location
    obj ||= self.send(:position) if self.respond_to? :position
    obj ||= self
    get_the_location obj        
  end
end

#to_pointsObject

convert hash or object to [x, y] of floats



4
5
6
7
# File 'lib/mongoid/geo/point.rb', line 4

def to_points
  v = self.kind_of?(Array) ? self.map {|p| p.kind_of?(Fixnum) ? p.to_f : p.extend(Mongoid::Geo::Point).to_point } : self
  v.flatten
end