Sha256: 54bcf8399625dd90190f53f0ec0845f7c93dbcd78a96dfa3c1f8acaaf04b9609

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

require 'geo_ruby'

module Mongoid
  #
  # Wrappers for GeoRuby
  # https://github.com/nofxx/georuby
  #
  module Geospatial
    # Wrapper to GeoRuby's Point
    Point.class_eval do
      # delegate :distance, to: :to_geo

      #
      # With GeoRuby support
      #
      # @return (GeoRuby::SimpleFeatures::Point)
      def to_geo
        return unless valid?

        GeoRuby::SimpleFeatures::Point.xy(x, y)
      end

      #
      # With GeoRuby support
      #
      # @return (Float)
      def geo_distance(other)
        to_geo.spherical_distance(other.to_geo)
      end
    end

    # Wrapper to GeoRuby's LineString
    LineString.class_eval do
      def to_geo
        GeoRuby::SimpleFeatures::LineString.from_coordinates(self)
      end
    end

    # Wrapper to GeoRuby's Polygon
    Polygon.class_eval do
      def to_geo
        GeoRuby::SimpleFeatures::Polygon.from_coordinates(self)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-geospatial-5.1.0 lib/mongoid/geospatial/wrappers/georuby.rb