Sha256: aadd546bab93298058a4e0f1128b172b0fba6b8cde52e2ca2e4dc7a702b3cbf9

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require "geocoder2/configuration"
require "geocoder2/query"
require "geocoder2/calculations"
require "geocoder2/exceptions"
require "geocoder2/cache"
require "geocoder2/request"
require "geocoder2/lookup"
require "geocoder2/models/active_record" if defined?(::ActiveRecord)
require "geocoder2/models/mongoid" if defined?(::Mongoid)
require "geocoder2/models/mongo_mapper" if defined?(::MongoMapper)

module Geocoder2
  extend self

  ##
  # Search for information about an address or a set of coordinates.
  #
  def search(query, options = {})
    query = Geocoder2::Query.new(query, options) unless query.is_a?(Geocoder2::Query)
    query.blank? ? [] : query.execute
  end

  ##
  # Look up the coordinates of the given street or IP address.
  #
  def coordinates(address, options = {})
    if (results = search(address, options)).size > 0
      results.first.coordinates
    end
  end

  ##
  # Look up the address of the given coordinates ([lat,lon])
  # or IP address (string).
  #
  def address(query, options = {})
    if (results = search(query, options)).size > 0
      results.first.address
    end
  end

  ##
  # The working Cache object, or +nil+ if none configured.
  #
  def cache
    warn "WARNING: Calling Geocoder2.cache is DEPRECATED. The #cache method now belongs to the Geocoder2::Lookup object."
    Geocoder2::Lookup.get(Geocoder2.config.lookup).cache
  end
end

# load Railtie if Rails exists
if defined?(Rails)
  require "geocoder2/railtie"
  Geocoder2::Railtie.insert
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geocoder2-0.1.1 lib/geocoder2.rb
geocoder2-0.1.0 lib/geocoder2.rb