Class: Graticule::Geocoder::Base
- Inherits:
-
Object
- Object
- Graticule::Geocoder::Base
- Includes:
- Comparable
- Defined in:
- lib/graticule/geocoder/base.rb
Overview
Abstract class for implementing geocoders.
Example
The following methods must be implemented in sublcasses:
initialize-
Sets @url to the service enpoint.
check_error-
Checks for errors in the server response.
parse_response-
Extracts information from the server response.
Optionally, you can also override
prepare_response-
Convert the string response into a different format
that gets passed on to
check_errorandparse_response.
If you have extra URL paramaters (application id, output type) or need to perform URL customization, override make_url.
class FakeGeocoder < Base
def initialize(appid)
@appid = appid
@url = URI.parse 'http://example.com/test'
end
def locate(query)
get :q => query
end
private
def check_error(xml)
raise Error, xml.elements['error'].text if xml.elements['error']
end
def make_url(params)
params[:appid] = @appid
super params
end
def parse_first(response)
# return Location
end
end
Direct Known Subclasses
Constant Summary collapse
- USER_AGENT =
"Mozilla/5.0 (compatible; Graticule/#{Graticule::Version::STRING}; http://graticule.rubyforge.org)"
Instance Attribute Summary collapse
-
#preference ⇒ Object
Returns the value of attribute preference.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
60 61 62 |
# File 'lib/graticule/geocoder/base.rb', line 60 def initialize raise NotImplementedError end |
Instance Attribute Details
#preference ⇒ Object
Returns the value of attribute preference.
58 59 60 |
# File 'lib/graticule/geocoder/base.rb', line 58 def preference @preference end |
Instance Method Details
#<=>(other) ⇒ Object
64 65 66 |
# File 'lib/graticule/geocoder/base.rb', line 64 def <=>(other) other.preference <=> preference end |