Class: Mongoid::Location::Point

Inherits:
Object
  • Object
show all
Includes:
Fields::Serializable
Defined in:
lib/mongoid_location/fields/point.rb,
lib/mongoid_location/fields/mongoid2/point.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.demongoize(object) ⇒ Object



17
18
19
20
21
# File 'lib/mongoid_location/fields/point.rb', line 17

def demongoize(object)
  return unless object && !object.empty?
  RGeo::Geographic.spherical_factory.point *object
  #["x"], object["y"]
end

.evolve(object) ⇒ Object

Converts the object that was supplied to a criteria and converts it into a database friendly form.



29
30
31
# File 'lib/mongoid_location/fields/point.rb', line 29

def evolve(object)
  object.respond_to?(:x) ? [object.x, object.y] : object
end

.instantiate(name, options = {}) ⇒ Object



6
7
8
# File 'lib/mongoid_location/fields/mongoid2/point.rb', line 6

def self.instantiate name, options = {}
  super
end

.mongoize(object) ⇒ Object



23
24
25
# File 'lib/mongoid_location/fields/point.rb', line 23

def mongoize(object)
  object.respond_to?(:x) ? [object.x, object.y] : object
end

Instance Method Details

#deserialize(object) ⇒ Object



14
15
16
17
# File 'lib/mongoid_location/fields/mongoid2/point.rb', line 14

def deserialize(object)
  return unless object && !object.empty?
  RGeo::Geographic.spherical_factory.point *object
end

#mongoizeObject



6
7
8
9
10
11
12
13
# File 'lib/mongoid_location/fields/point.rb', line 6

def mongoize
  self.respond_to?(:x) ? [x, y] : self
  # if object.respond_to? :x
  #   { "x" => object.x, "y" => object.y }
  # else
  #   { "x" => object[0], "y" => object[1] }
  # end
end

#serialize(object) ⇒ Object



10
11
12
# File 'lib/mongoid_location/fields/mongoid2/point.rb', line 10

def serialize(object)
  object.respond_to?(:x) ? [object.x, object.y] : object
end