Class: Graticule::Geocoder::Base

Inherits:
Object
  • Object
show all
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_error and parse_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_response(response)
  # return Location
end

end

Constant Summary collapse

USER_AGENT =
"Mozilla/5.0 (compatible; Graticule; http://graticule.rubyforge.org)"

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/graticule/geocoder/base.rb', line 56

def initialize
  raise NotImplementedError
end