module SoraGeocoding

This library takes into account the number of API calls and address lookup to get the latitude and longitude. The API uses the Geocoding API and the Yahoo! Geocoder API.

Constants

VERSION

Public Class Methods

config() click to toggle source

Read-only access to the singleton's config data.

# File lib/sora_geocoding/configuration.rb, line 33
def self.config
  Configuration.instance.data
end
config_for_lookup(lookup_name) click to toggle source

Read-only access to specific config data.

# File lib/sora_geocoding/configuration.rb, line 40
def self.config_for_lookup(lookup_name)
  data = config.clone
  data.select! { |key, _value| Configuration::OPTIONS.include?(key) }
  data.merge!(config[lookup_name]) if config.key?(lookup_name)
  data
end
configure(options = nil) click to toggle source

Configuration options should be set by passing a hash:

SoraGeocoding.configure(
  :timeout     => 5,
  :site        => 'yahoo',
  :yahoo_appid => '2a9fsa983jaslfj982fjasd'
)
# File lib/sora_geocoding/configuration.rb, line 26
def self.configure(options = nil)
  options ? Configuration.instance.configure(options) : config
end
coordinates(address, options = {}) click to toggle source

Look up the coordinates of the given street or IP address.

# File lib/sora_geocoding.rb, line 29
def self.coordinates(address, options = {})
  results = search(address, options)
  return if results.nil?

  { site: results[:site], coordinates: site_specific_coordinates(results[:site], results[:data]) }
end
geohash(latitude, longitude) click to toggle source

Generate a Geohash from latitude and longitude.

# File lib/sora_geocoding.rb, line 39
def self.geohash(latitude, longitude)
  geohash = Geohash.new(latitude, longitude)
  geohash.encode
end
log(level, message) click to toggle source
# File lib/sora_geocoding/logger.rb, line 5
def self.log(level, message)
  Logger.instance.log(level, message)
end

Private Class Methods

site_map() click to toggle source
# File lib/sora_geocoding.rb, line 50
def site_map
  {
    'yahoo' => 'YahooGeocoder',
    'geocoding' => 'Geocoding'
  }
end
site_specific_coordinates(site, data) click to toggle source
# File lib/sora_geocoding.rb, line 46
def site_specific_coordinates(site, data)
  SoraGeocoding::Results.const_get(site_map[site]).new(data).coordinates
end