Class: Geocoder::Lookup::Base
- Inherits:
-
Object
- Object
- Geocoder::Lookup::Base
- Defined in:
- lib/geocoder/lookups/base.rb
Direct Known Subclasses
Bing, Freegeoip, GeocoderCa, Google, Mapquest, Maxmind, Nominatim, Test, Yahoo, Yandex
Instance Method Summary collapse
-
#handle ⇒ Object
Symbol which is used in configuration to refer to this Lookup.
-
#map_link_url(coordinates) ⇒ Object
Return the URL for a map of the given coordinates.
-
#name ⇒ Object
Human-readable name of the geocoding API.
-
#query_url(query) ⇒ Object
URL to use for querying the geocoding engine.
-
#required_api_key_parts ⇒ Object
Array containing string descriptions of keys required by the API.
-
#search(query, options = {}) ⇒ Object
Query the geocoding API and return a Geocoder::Result object.
Instance Method Details
#handle ⇒ Object
Symbol which is used in configuration to refer to this Lookup.
29 30 31 32 |
# File 'lib/geocoder/lookups/base.rb', line 29 def handle str = self.class.to_s str[str.rindex(':')+1..-1].gsub(/([a-z\d]+)([A-Z])/,'\1_\2').downcase.to_sym end |
#map_link_url(coordinates) ⇒ Object
Return the URL for a map of the given coordinates.
Not necessarily implemented by all subclasses as only some lookups also provide maps.
57 58 59 |
# File 'lib/geocoder/lookups/base.rb', line 57 def map_link_url(coordinates) nil end |
#name ⇒ Object
Human-readable name of the geocoding API.
22 23 24 |
# File 'lib/geocoder/lookups/base.rb', line 22 def name fail end |
#query_url(query) ⇒ Object
URL to use for querying the geocoding engine.
72 73 74 |
# File 'lib/geocoder/lookups/base.rb', line 72 def query_url(query) fail end |
#required_api_key_parts ⇒ Object
Array containing string descriptions of keys required by the API. Empty array if keys are optional or not required.
65 66 67 |
# File 'lib/geocoder/lookups/base.rb', line 65 def required_api_key_parts [] end |
#search(query, options = {}) ⇒ Object
Query the geocoding API and return a Geocoder::Result object. Returns nil
on timeout or error.
Takes a search string (eg: “Mississippi Coast Coliseumf, Biloxi, MS”, “205.128.54.202”) for geocoding, or coordinates (latitude, longitude) for reverse geocoding. Returns an array of Geocoder::Result
s.
42 43 44 45 46 47 48 49 |
# File 'lib/geocoder/lookups/base.rb', line 42 def search(query, = {}) query = Geocoder::Query.new(query, ) unless query.is_a?(Geocoder::Query) results(query).map{ |r| result = result_class.new(r) result.cache_hit = @cache_hit if cache result } end |