Sha256: 2474aafd244190048a17b033bd491e1b4dd2fda66ed6cd7ec5f5ff65681f2fc6
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
module Geocoder2 module Lookup extend self ## # Array of valid Lookup service names. # def all_services street_services + ip_services end ## # Array of valid Lookup service names, excluding :test. # def all_services_except_test all_services - [:test] end ## # All street address lookup services, default first. # def street_services [ :dstk, :esri, :google, :google_premier, :yahoo, :bing, :geocoder_ca, :geocoder_us, :yandex, :nominatim, :mapquest, :ovi, :baidu, :test ] end ## # All IP address lookup services, default first. # def ip_services [:freegeoip, :maxmind] end ## # Retrieve a Lookup object from the store. # Use this instead of Geocoder2::Lookup::X.new to get an # already-configured Lookup object. # def get(name) @services = {} unless defined?(@services) @services[name] = spawn(name) unless @services.include?(name) @services[name] end private # ----------------------------------------------------------------- ## # Spawn a Lookup of the given name. # def spawn(name) if all_services.include?(name) Geocoder2::Lookup.const_get(classify_name(name)).new else valids = all_services.map(&:inspect).join(", ") raise ConfigurationError, "Please specify a valid lookup for Geocoder2 " + "(#{name.inspect} is not one of: #{valids})." end end ## # Convert an "underscore" version of a name into a "class" version. # def classify_name(filename) filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join end end end Geocoder2::Lookup.all_services.each do |name| require "geocoder2/lookups/#{name}" end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geocoder2-0.1.1 | lib/geocoder2/lookup.rb |
geocoder2-0.1.0 | lib/geocoder2/lookup.rb |