Sha256: df36d39b819ae7d1147c2e4f72fe5ffa7f057c7357da84b0d6232b9ed0bbd8db

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'mongoid_spacial/spacial/core_ext'
require 'mongoid_spacial/spacial/formulas'
module Mongoid
  module Spacial
    autoload :Document,          'mongoid_spacial/spacial/document'
    autoload :GeoNear,           'mongoid_spacial/spacial/geo_near'

    EARTH_RADIUS_KM = 6371 # taken directly from mongodb

    EARTH_RADIUS = {
      :km => EARTH_RADIUS_KM,
      :m  => EARTH_RADIUS_KM*1000,
      :mi => EARTH_RADIUS_KM*0.621371192, # taken directly from mongodb
      :ft => EARTH_RADIUS_KM*5280*0.621371192,
    }

    LNG_SYMBOLS = [:x, :lon, :long, :lng, :longitude]
    LAT_SYMBOLS = [:y, :lat, :latitude]

    def distance(p1,p2,unit = nil, formula = nil)
      formula ||= self.distance_formula
      unit = earth_radius[unit] if unit.kind_of?(Symbol) && earth_radius[unit]
      rads = Formulas.send(formula, p1, p2)
      (unit.kind_of?(Numeric)) ? unit*rads : rads
    end
    mattr_accessor :lng_symbols
    @@lng_symbols = LNG_SYMBOLS.dup

    mattr_accessor :lat_symbols
    @@lat_symbols = LAT_SYMBOLS.dup

    mattr_accessor :earth_radius
    @@earth_radius = EARTH_RADIUS.dup

    mattr_accessor :distance_formula
    @@distance_formula = :n_vector

    mattr_accessor :paginator
    @@paginator = :array

    mattr_accessor :default_per_page
    @@default_per_page = 25
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid_spacial-0.1.1 lib/mongoid_spacial/spacial.rb