lib/mongoid_geospatial/wrappers/georuby.rb in mongoid_geospatial-2.5.1 vs lib/mongoid_geospatial/wrappers/georuby.rb in mongoid_geospatial-2.7.0
- old
+ new
@@ -1,18 +1,34 @@
-require 'georuby'
+require 'geo_ruby'
# require 'mongoid_geospatial/extensions/georuby'
module Mongoid
module Geospatial
class Point
+ delegate :distance, :to => :to_geo
+
def to_geo
- GeoRuby::SimpleFeatures::Point.from_x_y(x, y)
+ GeoRuby::SimpleFeatures::Point.xy(x, y)
end
+
+ def distance other
+ to_geo.spherical_distance(other.to_geo)
+ end
+
+ def self.mongoize(obj)
+ case obj
+ when GeoRuby::SimpleFeatures::Point then [obj.x, obj.y]
+ when Point then obj.mongoize
+ when Array then obj.to_xy
+ when Hash then obj.to_xy
+ else obj
+ end
+ end
end
- class Line < Array
+ class Line < GeometryField
def to_geo
GeoRuby::SimpleFeatures::LineString.from_array(self)
end
end