Sha256: 72879cf2dab9b90cb7119287baa3c542eecf807c5cd889607ffd9d74edd0a036

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

module Mongoid
  module Geospatial
    class Point

      include Mongoid::Fields::Serializable

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

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

#       -    self.spacial_fields ||= []
# -    self.spacial_fields << field.name.to_sym if self.spacial_fields.kind_of? Array
# -
# -    define_method "distance_from_#{field.name}" do |*args|
# -      self.distance_from(field.name, *args)
# -    end
# -
# -    define_method field.name do
# -      output = self[field.name] || [nil,nil]
# -      output = {lng_meth => output[0], lat_meth => output[1]} unless options[:return_array]
# -      return options[:class].new(output) if options[:class]
# -      output
# -    end
# -
# -    define_method "#{field.name}=" do |arg|
# -      if arg.kind_of?(Hash) && arg[lng_meth] && arg[lat_meth]
# -        arg = [arg[lng_meth].to_f, arg[lat_meth].to_f]
# -      elsif arg.respond_to?(:to_lng_lat)
# -        arg = arg.to_lng_lat
# -      end
# -      self[field.name]=arg
# -      arg = [nil,nil] if arg.nil?
# -      return arg[0..1] if options[:return_array]
# -      h = {lng_meth => arg[0], lat_meth => arg[1]}
# -      return h if options[:class].blank?
# -      options[:class].new(h)

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid_geospatial-1.0.0rc1 lib/mongoid_geospatial/fields/point.rb
mongoid_geospatial-1.0.0rc0 lib/mongoid_geospatial/fields/point.rb