module Geocoder

def self.config


Read-only access to the singleton's config data.
#
def self.config
  Configuration.instance.data
end

def self.config_for_lookup(lookup_name)


Read-only access to lookup-specific config data.
#
def self.config_for_lookup(lookup_name)
  data = config.clone
  data.reject!{ |key,value| !Configuration::OPTIONS.include?(key) }
  if config.has_key?(lookup_name)
    data.merge!(config[lookup_name])
  end
  data
end

def self.configure(options = nil, &block)


)
:units => :km
:api_key => "2a9fsa983jaslfj982fjasd",
:lookup => :yandex,
:timeout => 5,
Geocoder.configure(

Configuration options should be set by passing a hash:
#
def self.configure(options = nil, &block)
  if block_given?
    warn "WARNING: Passing a block to Geocoder.configure is DEPRECATED. Please pass a hash instead (eg: Geocoder.configure(:units => ..., :api_key => ...))."
    block.call(Configuration.instance)
  elsif !options.nil?
    Configuration.instance.configure(options)
  else
    warn "WARNING: Use of Geocoder.configure to read or write single config options is DEPRECATED. To write to the config please pass a hash (eg: Geocoder.configure(:units => ...)). To read config options please use the Geocoder.config object (eg: Geocoder.config.units)."
    Configuration.instance
  end
end

def address(query, options = {})


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

def cache


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

def coordinates(address, options = {})


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

def search(query, options = {})


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