graticule 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,7 @@ lib/graticule/geocoder/google.rb
20
20
  lib/graticule/geocoder/host_ip.rb
21
21
  lib/graticule/geocoder/local_search_maps.rb
22
22
  lib/graticule/geocoder/meta_carta.rb
23
+ lib/graticule/geocoder/multi.rb
23
24
  lib/graticule/geocoder/postcode_anywhere.rb
24
25
  lib/graticule/geocoder/rest.rb
25
26
  lib/graticule/geocoder/yahoo.rb
@@ -63,6 +64,7 @@ test/unit/graticule/geocoder/google_test.rb
63
64
  test/unit/graticule/geocoder/host_ip_test.rb
64
65
  test/unit/graticule/geocoder/local_search_maps_test.rb
65
66
  test/unit/graticule/geocoder/meta_carta_test.rb
67
+ test/unit/graticule/geocoder/multi_test.rb
66
68
  test/unit/graticule/geocoder/postcode_anywhere_test.rb
67
69
  test/unit/graticule/geocoder/yahoo_test.rb
68
70
  test/unit/graticule/geocoder_test.rb
@@ -0,0 +1,46 @@
1
+ module Graticule #:nodoc:
2
+ module Geocoder #:nodoc:
3
+ class Multi
4
+
5
+ # The Multi geocoder allows you to use multiple geocoders in succession.
6
+ #
7
+ # geocoder = Graticule.service(:multi).new(
8
+ # Graticule.service(:google).new("api_key"),
9
+ # Graticule.service(:yahoo).new("api_key"),
10
+ # )
11
+ # geocoder.locate '49423' # <= tries geocoders in succession
12
+ #
13
+ # The Multi geocoder will try the geocoders in order if a Graticule::AddressError
14
+ # is raised. You can customize this behavior by passing in a block to the Multi
15
+ # geocoder. For example, to try the geocoders until one returns a result with a
16
+ # high enough precision:
17
+ #
18
+ # geocoder = Graticule.service(:multi).new(geocoders) do |result|
19
+ # [:address, :street].include?(result.precision)
20
+ # end
21
+ #
22
+ # Geocoders will be tried in order until the block returned true for one of the results
23
+ #
24
+ def initialize(*geocoders, &acceptable)
25
+ @acceptable = acceptable || lambda { true }
26
+ @geocoders = geocoders.flatten
27
+ end
28
+
29
+ def locate(address)
30
+ last_error = nil
31
+ @geocoders.each do |geocoder|
32
+ begin
33
+ result = geocoder.locate address
34
+ return result if @acceptable.call(result)
35
+ rescue Error => e
36
+ last_error = e
37
+ rescue Errno::ECONNREFUSED
38
+ logger.error("Connection refused to #{service}")
39
+ end
40
+ end
41
+ raise last_error || AddressError.new("Couldn't find '#{address}' with any of the services")
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -2,7 +2,7 @@ module Graticule #:nodoc:
2
2
  module Version #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: graticule
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.5
6
+ version: 0.2.6
7
7
  date: 2007-09-12 00:00:00 -04:00
8
8
  summary: API for using all the popular geocoding services.
9
9
  require_paths:
@@ -51,6 +51,7 @@ files:
51
51
  - lib/graticule/geocoder/host_ip.rb
52
52
  - lib/graticule/geocoder/local_search_maps.rb
53
53
  - lib/graticule/geocoder/meta_carta.rb
54
+ - lib/graticule/geocoder/multi.rb
54
55
  - lib/graticule/geocoder/postcode_anywhere.rb
55
56
  - lib/graticule/geocoder/rest.rb
56
57
  - lib/graticule/geocoder/yahoo.rb
@@ -94,6 +95,7 @@ files:
94
95
  - test/unit/graticule/geocoder/host_ip_test.rb
95
96
  - test/unit/graticule/geocoder/local_search_maps_test.rb
96
97
  - test/unit/graticule/geocoder/meta_carta_test.rb
98
+ - test/unit/graticule/geocoder/multi_test.rb
97
99
  - test/unit/graticule/geocoder/postcode_anywhere_test.rb
98
100
  - test/unit/graticule/geocoder/yahoo_test.rb
99
101
  - test/unit/graticule/geocoder_test.rb