Module: Geocoder
- Defined in:
- lib/geocoder.rb,
lib/geocoder/cli.rb,
lib/geocoder/sql.rb,
lib/geocoder/cache.rb,
lib/geocoder/query.rb,
lib/geocoder/logger.rb,
lib/geocoder/lookup.rb,
lib/geocoder/railtie.rb,
lib/geocoder/request.rb,
lib/geocoder/version.rb,
lib/maxmind_database.rb,
lib/geocoder/esri_token.rb,
lib/geocoder/exceptions.rb,
lib/geocoder/ip_address.rb,
lib/geocoder/models/base.rb,
lib/geocoder/stores/base.rb,
lib/geocoder/calculations.rb,
lib/geocoder/lookups/base.rb,
lib/geocoder/lookups/test.rb,
lib/geocoder/results/base.rb,
lib/geocoder/results/test.rb,
lib/geocoder/configuration.rb,
lib/geocoder/kernel_logger.rb,
lib/geocoder/lookups/geoip2.rb,
lib/geocoder/models/mongoid.rb,
lib/geocoder/results/geoip2.rb,
lib/geocoder/models/mongo_base.rb,
lib/geocoder/configuration_hash.rb,
lib/geocoder/models/mongo_mapper.rb,
lib/geocoder/models/active_record.rb,
lib/geocoder/lookups/geoportail_lu.rb,
lib/generators/geocoder/migration_version.rb,
lib/geocoder/lookups/google_places_search.rb,
lib/geocoder/results/google_places_search.rb,
lib/geocoder/lookups/google_places_details.rb,
lib/geocoder/results/google_places_details.rb,
lib/generators/geocoder/config/config_generator.rb,
lib/generators/geocoder/maxmind/geolite_city_generator.rb,
lib/generators/geocoder/maxmind/geolite_country_generator.rb
Defined Under Namespace
Modules: Calculations, Generators, Lookup, MaxmindDatabase, Model, Request, Result, Sql, Store Classes: Cache, Cli, ConfigGenerator, Configuration, ConfigurationError, ConfigurationHash, Error, EsriToken, InvalidApiKey, InvalidRequest, IpAddress, KernelLogger, Logger, LookupTimeout, NetworkError, OverQueryLimitError, Query, Railtie, RequestDenied, ResponseParseError, ServiceUnavailable
Constant Summary collapse
- VERSION =
"2.0.0"
Class Method Summary collapse
-
.address(query, options = {}) ⇒ Object
Look up the address of the given coordinates ([lat,lon]) or IP address (string).
-
.config ⇒ Object
Read-only access to the singleton’s config data.
-
.config_for_lookup(lookup_name) ⇒ Object
Read-only access to lookup-specific config data.
-
.configure(options = nil, &block) ⇒ Object
Configuration options should be set by passing a hash:.
-
.coordinates(address, options = {}) ⇒ Object
Look up the coordinates of the given street or IP address.
- .log(level, message) ⇒ Object
-
.merge_into_lookup_config(lookup_name, options) ⇒ Object
Merge the given hash into a lookup’s existing configuration.
-
.search(query, options = {}) ⇒ Object
Search for information about an address or a set of coordinates.
Class Method Details
.address(query, options = {}) ⇒ Object
Look up the address of the given coordinates ([lat,lon]) or IP address (string).
38 39 40 41 42 |
# File 'lib/geocoder.rb', line 38 def self.address(query, = {}) if (results = search(query, )).size > 0 results.first.address end end |
.config ⇒ Object
Read-only access to the singleton’s config data.
25 26 27 |
# File 'lib/geocoder/configuration.rb', line 25 def self.config Configuration.instance.data end |
.config_for_lookup(lookup_name) ⇒ Object
Read-only access to lookup-specific config data.
32 33 34 35 36 37 38 39 |
# File 'lib/geocoder/configuration.rb', line 32 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 |
.configure(options = nil, &block) ⇒ Object
Configuration options should be set by passing a hash:
Geocoder.configure(
:timeout => 5,
:lookup => :yandex,
:api_key => "2a9fsa983jaslfj982fjasd",
:units => :km
)
16 17 18 19 20 |
# File 'lib/geocoder/configuration.rb', line 16 def self.configure( = nil, &block) if !.nil? Configuration.instance.configure() end end |
.coordinates(address, options = {}) ⇒ Object
Look up the coordinates of the given street or IP address.
28 29 30 31 32 |
# File 'lib/geocoder.rb', line 28 def self.coordinates(address, = {}) if (results = search(address, )).size > 0 results.first.coordinates end end |
.log(level, message) ⇒ Object
5 6 7 |
# File 'lib/geocoder/logger.rb', line 5 def self.log(level, ) Logger.instance.log(level, ) end |
.merge_into_lookup_config(lookup_name, options) ⇒ Object
Merge the given hash into a lookup’s existing configuration.
44 45 46 47 |
# File 'lib/geocoder/configuration.rb', line 44 def self.merge_into_lookup_config(lookup_name, ) base = Geocoder.config[lookup_name] Geocoder.configure(lookup_name => base.merge()) end |