Class: Mongoid::Geospatial::Point
- Inherits:
-
Object
- Object
- Mongoid::Geospatial::Point
- Includes:
- Enumerable
- Defined in:
- lib/mongoid_geospatial/fields/point.rb,
lib/mongoid_geospatial/wrappers/rgeo.rb,
lib/mongoid_geospatial/wrappers/georuby.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
-
.demongoize(object) ⇒ Object
Database -> Object.
-
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria into a database friendly form.
- .mongoize(obj) ⇒ Object
Instance Method Summary collapse
- #[](args) ⇒ Object
- #distance(other) ⇒ Object
- #each {|x| ... } ⇒ Object
-
#initialize(x = nil, y = nil) ⇒ Point
constructor
A new instance of Point.
-
#mongoize ⇒ Object
Object -> Database.
- #radius(r = 1) ⇒ Object
- #radius_sphere(r = 1, unit = :km) ⇒ Object
-
#to_a ⇒ Object
Object -> Database.
- #to_geo ⇒ Object
- #to_hsh(xl = :x, yl = :y) ⇒ Object (also: #to_hash)
-
#to_xy ⇒ Object
Object -> Database.
Constructor Details
#initialize(x = nil, y = nil) ⇒ Point
Returns a new instance of Point.
7 8 9 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 7 def initialize(x=nil, y=nil) @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 5 def y @y end |
Class Method Details
.demongoize(object) ⇒ Object
Database -> Object
66 67 68 69 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 66 def demongoize(object) return unless object Point.new(*object) end |
.evolve(object) ⇒ Object
Converts the object that was supplied to a criteria into a database friendly form.
82 83 84 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 82 def evolve(object) object.respond_to?(:x) ? object.mongoize : object end |
Instance Method Details
#[](args) ⇒ Object
18 19 20 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 18 def [](args) mongoize[args] end |
#distance(other) ⇒ Object
12 13 14 |
# File 'lib/mongoid_geospatial/wrappers/rgeo.rb', line 12 def distance other to_geo.distance other.to_geo end |
#each {|x| ... } ⇒ Object
22 23 24 25 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 22 def each yield x yield y end |
#mongoize ⇒ Object
Object -> Database
12 13 14 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 12 def mongoize [x, y] end |
#radius(r = 1) ⇒ Object
32 33 34 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 32 def radius r = 1 [mongoize, r] end |
#radius_sphere(r = 1, unit = :km) ⇒ Object
36 37 38 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 36 def radius_sphere r = 1, unit = :km radius r.to_f/Mongoid::Geospatial.earth_radius[unit] end |
#to_a ⇒ Object
Object -> Database
15 16 17 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 15 def mongoize [x, y] end |
#to_geo ⇒ Object
8 9 10 |
# File 'lib/mongoid_geospatial/wrappers/rgeo.rb', line 8 def to_geo RGeo::Geographic.spherical_factory.point x, y end |
#to_hsh(xl = :x, yl = :y) ⇒ Object Also known as: to_hash
27 28 29 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 27 def to_hsh xl = :x, yl = :y {xl => x, yl => y} end |
#to_xy ⇒ Object
Object -> Database
16 17 18 |
# File 'lib/mongoid_geospatial/fields/point.rb', line 16 def mongoize [x, y] end |