graticule 1.0.0.pre → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/VERSION +1 -1
- data/graticule.gemspec +5 -2
- data/lib/graticule.rb +1 -0
- data/lib/graticule/geocoder/google.rb +10 -10
- data/lib/graticule/geocoder/mapquest.rb +13 -13
- data/lib/graticule/geocoder/multi.rb +1 -4
- data/lib/graticule/geocoder/multimap.rb +7 -7
- data/lib/graticule/geocoder/yahoo.rb +8 -8
- data/lib/graticule/location.rb +5 -1
- data/lib/graticule/precision.rb +46 -0
- data/test/graticule/geocoder/multimap_test.rb +2 -2
- data/test/graticule/location_test.rb +5 -0
- data/test/graticule/precision_test.rb +37 -0
- metadata +5 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
1
|
+
1.0.0.pre2
|
data/graticule.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{graticule}
|
8
|
-
s.version = "1.0.0.
|
8
|
+
s.version = "1.0.0.pre2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brandon Keepers"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-04}
|
13
13
|
s.default_executable = %q{geocode}
|
14
14
|
s.description = %q{Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.}
|
15
15
|
s.email = %q{brandon@opensoul.org}
|
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
"lib/graticule/geocoder/multimap.rb",
|
51
51
|
"lib/graticule/geocoder/yahoo.rb",
|
52
52
|
"lib/graticule/location.rb",
|
53
|
+
"lib/graticule/precision.rb",
|
53
54
|
"site/index.html",
|
54
55
|
"site/plugin.html",
|
55
56
|
"site/stylesheets/style.css",
|
@@ -100,6 +101,7 @@ Gem::Specification.new do |s|
|
|
100
101
|
"test/graticule/geocoder/yahoo_test.rb",
|
101
102
|
"test/graticule/geocoder_test.rb",
|
102
103
|
"test/graticule/location_test.rb",
|
104
|
+
"test/graticule/precision_test.rb",
|
103
105
|
"test/mocks/uri.rb",
|
104
106
|
"test/test_helper.rb"
|
105
107
|
]
|
@@ -172,6 +174,7 @@ Gem::Specification.new do |s|
|
|
172
174
|
"test/graticule/geocoder/yahoo_test.rb",
|
173
175
|
"test/graticule/geocoder_test.rb",
|
174
176
|
"test/graticule/location_test.rb",
|
177
|
+
"test/graticule/precision_test.rb",
|
175
178
|
"test/mocks",
|
176
179
|
"test/mocks/uri.rb",
|
177
180
|
"test/test_helper.rb"
|
data/lib/graticule.rb
CHANGED
@@ -14,16 +14,16 @@ module Graticule #:nodoc:
|
|
14
14
|
|
15
15
|
# http://www.google.com/apis/maps/documentation/reference.html#GGeoAddressAccuracy
|
16
16
|
PRECISION = {
|
17
|
-
0 =>
|
18
|
-
1 =>
|
19
|
-
2 =>
|
20
|
-
3 =>
|
21
|
-
4 =>
|
22
|
-
5 =>
|
23
|
-
6 =>
|
24
|
-
7 =>
|
25
|
-
8 =>
|
26
|
-
9 =>
|
17
|
+
0 => Precision::Unknown, # Unknown location.
|
18
|
+
1 => Precision::Country, # Country level accuracy.
|
19
|
+
2 => Precision::Region, # Region (state, province, prefecture, etc.) level accuracy.
|
20
|
+
3 => Precision::Region, # Sub-region (county, municipality, etc.) level accuracy.
|
21
|
+
4 => Precision::Locality, # Town (city, village) level accuracy.
|
22
|
+
5 => Precision::PostalCode, # Post code (zip code) level accuracy.
|
23
|
+
6 => Precision::Street, # Street level accuracy.
|
24
|
+
7 => Precision::Street, # Intersection level accuracy.
|
25
|
+
8 => Precision::Address, # Address level accuracy.
|
26
|
+
9 => Precision::Premise # Premise (building name, property name, shopping center, etc.) level accuracy.
|
27
27
|
}
|
28
28
|
|
29
29
|
def initialize(key)
|
@@ -13,19 +13,19 @@ module Graticule #:nodoc:
|
|
13
13
|
# I would link to the documentation here, but there is none that will do anything but confuse you.
|
14
14
|
|
15
15
|
PRECISION = {
|
16
|
-
'L1' =>
|
17
|
-
'I1' =>
|
18
|
-
'B1' =>
|
19
|
-
'B2' =>
|
20
|
-
'B3' =>
|
21
|
-
'Z3' =>
|
22
|
-
'Z4' =>
|
23
|
-
'Z2' =>
|
24
|
-
'Z1' =>
|
25
|
-
'A5' =>
|
26
|
-
'A4' =>
|
27
|
-
'A3' =>
|
28
|
-
'A1' =>
|
16
|
+
'L1' => Precision::Address,
|
17
|
+
'I1' => Precision::Street,
|
18
|
+
'B1' => Precision::Street,
|
19
|
+
'B2' => Precision::Street,
|
20
|
+
'B3' => Precision::Street,
|
21
|
+
'Z3' => Precision::PostalCode,
|
22
|
+
'Z4' => Precision::PostalCode,
|
23
|
+
'Z2' => Precision::PostalCode,
|
24
|
+
'Z1' => Precision::PostalCode,
|
25
|
+
'A5' => Precision::Locality,
|
26
|
+
'A4' => Precision::Region,
|
27
|
+
'A3' => Precision::Region,
|
28
|
+
'A1' => Precision::Country
|
29
29
|
}
|
30
30
|
|
31
31
|
def initialize(client_id, password)
|
@@ -45,12 +45,9 @@ module Graticule #:nodoc:
|
|
45
45
|
result = geocoder.locate address
|
46
46
|
end
|
47
47
|
result if @acceptable.call(result)
|
48
|
-
rescue
|
48
|
+
rescue => e
|
49
49
|
last_error = e
|
50
50
|
nil
|
51
|
-
rescue Errno::ECONNREFUSED
|
52
|
-
logger.error("Connection refused to #{service}")
|
53
|
-
nil
|
54
51
|
end
|
55
52
|
end
|
56
53
|
end
|
@@ -10,12 +10,12 @@ module Graticule #:nodoc:
|
|
10
10
|
# http://www.multimap.com/share/documentation/clientzone/gqcodes.htm
|
11
11
|
|
12
12
|
PRECISION = {
|
13
|
-
6 =>
|
14
|
-
5 =>
|
15
|
-
4 =>
|
16
|
-
3 =>
|
17
|
-
2 =>
|
18
|
-
1 =>
|
13
|
+
6 => Precision::Country,
|
14
|
+
5 => Precision::Region,
|
15
|
+
4 => Precision::PostalCode,
|
16
|
+
3 => Precision::Locality,
|
17
|
+
2 => Precision::Street,
|
18
|
+
1 => Precision::Address
|
19
19
|
}
|
20
20
|
|
21
21
|
# Web services initializer.
|
@@ -40,7 +40,7 @@ module Graticule #:nodoc:
|
|
40
40
|
when Location
|
41
41
|
get "street" => location.street,
|
42
42
|
"region" => location.region,
|
43
|
-
"city" => location.
|
43
|
+
"city" => location.locality,
|
44
44
|
"postalCode" => location.postal_code,
|
45
45
|
"countryCode" => location.country
|
46
46
|
end
|
@@ -7,14 +7,14 @@ module Graticule #:nodoc:
|
|
7
7
|
class Yahoo < Base
|
8
8
|
|
9
9
|
PRECISION = {
|
10
|
-
"country" =>
|
11
|
-
"state" =>
|
12
|
-
"city" =>
|
13
|
-
"zip+4" =>
|
14
|
-
"zip+2" =>
|
15
|
-
"zip" =>
|
16
|
-
"street" =>
|
17
|
-
"address" =>
|
10
|
+
"country" => Precision::Country,
|
11
|
+
"state" => Precision::Region,
|
12
|
+
"city" => Precision::Locality,
|
13
|
+
"zip+4" => Precision::PostalCode,
|
14
|
+
"zip+2" => Precision::PostalCode,
|
15
|
+
"zip" => Precision::PostalCode,
|
16
|
+
"street" => Precision::Street,
|
17
|
+
"address" => Precision::Address
|
18
18
|
}
|
19
19
|
|
20
20
|
# Web services initializer.
|
data/lib/graticule/location.rb
CHANGED
@@ -9,11 +9,15 @@ module Graticule
|
|
9
9
|
|
10
10
|
def initialize(attrs = {})
|
11
11
|
attrs.each do |key,value|
|
12
|
-
|
12
|
+
self.send("#{key}=", value)
|
13
13
|
end
|
14
14
|
self.precision ||= :unknown
|
15
15
|
end
|
16
16
|
|
17
|
+
def precision=(precision)
|
18
|
+
@precision = Precision.new(precision.to_s)
|
19
|
+
end
|
20
|
+
|
17
21
|
def attributes
|
18
22
|
[:latitude, :longitude, :street, :locality, :region, :postal_code, :country, :precision].inject({}) do |result,attr|
|
19
23
|
result[attr] = self.send(attr) unless self.send(attr).blank?
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Graticule
|
2
|
+
|
3
|
+
# Used to compare the precision of different geocoded locations
|
4
|
+
class Precision
|
5
|
+
include Comparable
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
NAMES = [
|
9
|
+
:unknown,
|
10
|
+
:country,
|
11
|
+
:region,
|
12
|
+
:locality,
|
13
|
+
:postal_code,
|
14
|
+
:street,
|
15
|
+
:address,
|
16
|
+
:premise
|
17
|
+
]
|
18
|
+
|
19
|
+
def initialize(name)
|
20
|
+
@name = name.to_sym
|
21
|
+
raise ArgumentError, "#{name} is not a valid precision. Use one of #{NAMES.inspect}" unless NAMES.include?(@name)
|
22
|
+
end
|
23
|
+
|
24
|
+
Unknown = Precision.new(:unknown)
|
25
|
+
Country = Precision.new(:country)
|
26
|
+
Region = Precision.new(:region)
|
27
|
+
Locality = Precision.new(:locality)
|
28
|
+
PostalCode = Precision.new(:postal_code)
|
29
|
+
Street = Precision.new(:street)
|
30
|
+
Address = Precision.new(:address)
|
31
|
+
Premise = Precision.new(:premise)
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
@name.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def <=>(other)
|
38
|
+
other = Precision.new(other) unless other.is_a?(Precision)
|
39
|
+
NAMES.index(self.name) <=> NAMES.index(other.name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(other)
|
43
|
+
(self <=> other) == 0
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -32,8 +32,8 @@ module Graticule
|
|
32
32
|
|
33
33
|
def test_url_from_location
|
34
34
|
prepare_response(:success)
|
35
|
-
@geocoder.locate(:street => 'Oxford Street', :
|
36
|
-
assert_equal 'http://clients.multimap.com/API/geocode/1.2/API_KEY?city
|
35
|
+
@geocoder.locate(:street => 'Oxford Street', :locality => 'London')
|
36
|
+
assert_equal 'http://clients.multimap.com/API/geocode/1.2/API_KEY?city=London&countryCode=&postalCode=®ion=&street=Oxford%20Street', URI::HTTP.uris.first
|
37
37
|
end
|
38
38
|
|
39
39
|
|
@@ -77,5 +77,10 @@ module Graticule
|
|
77
77
|
chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
|
78
78
|
assert_equal 'America/Chicago', chicago.time_zone
|
79
79
|
end
|
80
|
+
|
81
|
+
def test_casts_precision
|
82
|
+
assert_equal Precision::Region, Location.new(:precision => :region).precision
|
83
|
+
assert_equal Precision::Street, Location.new(:precision => Precision::Street).precision
|
84
|
+
end
|
80
85
|
end
|
81
86
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Graticule
|
4
|
+
class PrecisionTest < Test::Unit::TestCase
|
5
|
+
def test_constants_exist
|
6
|
+
%w(
|
7
|
+
Unknown
|
8
|
+
Country
|
9
|
+
Region
|
10
|
+
Locality
|
11
|
+
PostalCode
|
12
|
+
Street
|
13
|
+
Address
|
14
|
+
Premise
|
15
|
+
).each do |const|
|
16
|
+
assert Precision.const_defined?(const), "Can't find #{const}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_can_compare_precisions
|
21
|
+
assert Precision::Country < Precision::Region
|
22
|
+
assert Precision::Country > Precision::Unknown
|
23
|
+
assert Precision::Country == Precision::Country
|
24
|
+
assert Precision::Country == Precision.new(:country)
|
25
|
+
assert Precision::Country != Precision::Premise
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_can_compare_against_symbols
|
29
|
+
assert Precision::Country < :region
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_can_compare_against_symbols
|
33
|
+
assert_raise(ArgumentError) { Precision::Unknown > :foo }
|
34
|
+
assert_raise(ArgumentError) { Precision::Unknown == :bar }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graticule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-04 00:00:00 -05:00
|
13
13
|
default_executable: geocode
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/graticule/geocoder/multimap.rb
|
74
74
|
- lib/graticule/geocoder/yahoo.rb
|
75
75
|
- lib/graticule/location.rb
|
76
|
+
- lib/graticule/precision.rb
|
76
77
|
- site/index.html
|
77
78
|
- site/plugin.html
|
78
79
|
- site/stylesheets/style.css
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- test/graticule/geocoder/yahoo_test.rb
|
124
125
|
- test/graticule/geocoder_test.rb
|
125
126
|
- test/graticule/location_test.rb
|
127
|
+
- test/graticule/precision_test.rb
|
126
128
|
- test/mocks/uri.rb
|
127
129
|
- test/test_helper.rb
|
128
130
|
has_rdoc: true
|
@@ -205,5 +207,6 @@ test_files:
|
|
205
207
|
- test/graticule/geocoder/yahoo_test.rb
|
206
208
|
- test/graticule/geocoder_test.rb
|
207
209
|
- test/graticule/location_test.rb
|
210
|
+
- test/graticule/precision_test.rb
|
208
211
|
- test/mocks/uri.rb
|
209
212
|
- test/test_helper.rb
|