pepe-graticule 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/CHANGELOG.txt +61 -0
- data/LICENSE.txt +30 -0
- data/Manifest.txt +84 -0
- data/README.txt +41 -0
- data/Rakefile +143 -0
- data/VERSION +1 -0
- data/bin/geocode +5 -0
- data/graticule.gemspec +146 -0
- data/init.rb +2 -0
- data/lib/graticule.rb +26 -0
- data/lib/graticule/cli.rb +64 -0
- data/lib/graticule/core_ext.rb +15 -0
- data/lib/graticule/distance.rb +18 -0
- data/lib/graticule/distance/haversine.rb +40 -0
- data/lib/graticule/distance/spherical.rb +52 -0
- data/lib/graticule/distance/vincenty.rb +76 -0
- data/lib/graticule/geocoder.rb +21 -0
- data/lib/graticule/geocoder/base.rb +112 -0
- data/lib/graticule/geocoder/bogus.rb +15 -0
- data/lib/graticule/geocoder/geocoder_ca.rb +54 -0
- data/lib/graticule/geocoder/geocoder_us.rb +51 -0
- data/lib/graticule/geocoder/google.rb +100 -0
- data/lib/graticule/geocoder/host_ip.rb +41 -0
- data/lib/graticule/geocoder/local_search_maps.rb +45 -0
- data/lib/graticule/geocoder/mapquest.rb +87 -0
- data/lib/graticule/geocoder/meta_carta.rb +33 -0
- data/lib/graticule/geocoder/multi.rb +46 -0
- data/lib/graticule/geocoder/multimap.rb +73 -0
- data/lib/graticule/geocoder/postcode_anywhere.rb +63 -0
- data/lib/graticule/geocoder/rest.rb +18 -0
- data/lib/graticule/geocoder/yahoo.rb +84 -0
- data/lib/graticule/location.rb +82 -0
- data/lib/graticule/version.rb +9 -0
- data/site/index.html +114 -0
- data/site/plugin.html +82 -0
- data/site/stylesheets/style.css +69 -0
- data/test/config.yml.default +36 -0
- data/test/fixtures/responses/geocoder_us/success.xml +18 -0
- data/test/fixtures/responses/geocoder_us/unknown.xml +1 -0
- data/test/fixtures/responses/google/badkey.xml +1 -0
- data/test/fixtures/responses/google/limit.xml +10 -0
- data/test/fixtures/responses/google/missing_address.xml +1 -0
- data/test/fixtures/responses/google/only_coordinates.xml +1 -0
- data/test/fixtures/responses/google/partial.xml +1 -0
- data/test/fixtures/responses/google/server_error.xml +10 -0
- data/test/fixtures/responses/google/success.xml +1 -0
- data/test/fixtures/responses/google/success_multiple_results.xml +88 -0
- data/test/fixtures/responses/google/unavailable.xml +1 -0
- data/test/fixtures/responses/google/unknown_address.xml +1 -0
- data/test/fixtures/responses/host_ip/private.txt +4 -0
- data/test/fixtures/responses/host_ip/success.txt +4 -0
- data/test/fixtures/responses/host_ip/unknown.txt +4 -0
- data/test/fixtures/responses/local_search_maps/empty.txt +1 -0
- data/test/fixtures/responses/local_search_maps/not_found.txt +1 -0
- data/test/fixtures/responses/local_search_maps/success.txt +1 -0
- data/test/fixtures/responses/mapquest/multi_result.xml +1 -0
- data/test/fixtures/responses/mapquest/success.xml +1 -0
- data/test/fixtures/responses/meta_carta/bad_address.xml +17 -0
- data/test/fixtures/responses/meta_carta/multiple.xml +33 -0
- data/test/fixtures/responses/meta_carta/success.xml +31 -0
- data/test/fixtures/responses/multimap/missing_params.xml +4 -0
- data/test/fixtures/responses/multimap/no_matches.xml +4 -0
- data/test/fixtures/responses/multimap/success.xml +19 -0
- data/test/fixtures/responses/postcode_anywhere/badkey.xml +9 -0
- data/test/fixtures/responses/postcode_anywhere/canada.xml +16 -0
- data/test/fixtures/responses/postcode_anywhere/empty.xml +16 -0
- data/test/fixtures/responses/postcode_anywhere/success.xml +16 -0
- data/test/fixtures/responses/postcode_anywhere/uk.xml +18 -0
- data/test/fixtures/responses/yahoo/success.xml +3 -0
- data/test/fixtures/responses/yahoo/unknown_address.xml +6 -0
- data/test/mocks/uri.rb +52 -0
- data/test/test_helper.rb +31 -0
- data/test/unit/graticule/distance_test.rb +58 -0
- data/test/unit/graticule/geocoder/geocoder_us_test.rb +43 -0
- data/test/unit/graticule/geocoder/geocoders.rb +56 -0
- data/test/unit/graticule/geocoder/google_test.rb +112 -0
- data/test/unit/graticule/geocoder/host_ip_test.rb +40 -0
- data/test/unit/graticule/geocoder/local_search_maps_test.rb +30 -0
- data/test/unit/graticule/geocoder/mapquest_test.rb +47 -0
- data/test/unit/graticule/geocoder/meta_carta_test.rb +44 -0
- data/test/unit/graticule/geocoder/multi_test.rb +43 -0
- data/test/unit/graticule/geocoder/multimap_test.rb +52 -0
- data/test/unit/graticule/geocoder/postcode_anywhere_test.rb +50 -0
- data/test/unit/graticule/geocoder/yahoo_test.rb +48 -0
- data/test/unit/graticule/geocoder_test.rb +27 -0
- data/test/unit/graticule/location_test.rb +79 -0
- metadata +167 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class HostIpTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@geocoder = HostIp.new
|
|
9
|
+
URI::HTTP.responses = []
|
|
10
|
+
URI::HTTP.uris = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_success
|
|
14
|
+
prepare_response :success
|
|
15
|
+
|
|
16
|
+
location = Location.new :country => 'US', :locality => 'Mountain View',
|
|
17
|
+
:region => 'CA', :latitude => 37.402, :longitude => -122.078
|
|
18
|
+
|
|
19
|
+
assert_equal location, @geocoder.locate('64.233.167.99')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_unknown
|
|
23
|
+
prepare_response :unknown
|
|
24
|
+
assert_raises(AddressError) { @geocoder.locate('127.0.0.1') }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_private_ip
|
|
28
|
+
prepare_response :private
|
|
29
|
+
assert_raises(AddressError) { @geocoder.locate('127.0.0.1') }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def prepare_response(id = :success)
|
|
35
|
+
URI::HTTP.responses << response('host_ip', id, 'txt')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class LocalSearchMapsTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@geocoder = LocalSearchMaps.new
|
|
9
|
+
URI::HTTP.responses = []
|
|
10
|
+
URI::HTTP.uris = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_success
|
|
14
|
+
prepare_response :success
|
|
15
|
+
|
|
16
|
+
location = Location.new :latitude => 51.510036, :longitude => -0.130427
|
|
17
|
+
|
|
18
|
+
assert_equal location, @geocoder.locate(:street => '48 Leicester Square',
|
|
19
|
+
:locality => 'London', :country => 'UK')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def prepare_response(id = :success)
|
|
25
|
+
URI::HTTP.responses << response('local_search_maps', id, 'txt')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class MapquestTest < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@geocoder = Mapquest.new('client_id', 'password')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_success
|
|
11
|
+
prepare_response(:success)
|
|
12
|
+
location = Location.new(
|
|
13
|
+
:country => "US",
|
|
14
|
+
:latitude => 44.152019,
|
|
15
|
+
:locality => "Lovell",
|
|
16
|
+
:longitude => -70.892706,
|
|
17
|
+
:postal_code => "04051-3919",
|
|
18
|
+
:precision => :address,
|
|
19
|
+
:region => "ME",
|
|
20
|
+
:street => "44 Allen Rd"
|
|
21
|
+
)
|
|
22
|
+
assert_equal(location, @geocoder.locate('44 Allen Rd., Lovell, ME 04051'))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_multi_result
|
|
26
|
+
prepare_response(:multi_result)
|
|
27
|
+
location = Location.new(
|
|
28
|
+
:country => "US",
|
|
29
|
+
:latitude => 40.925598,
|
|
30
|
+
:locality => "Stony Brook",
|
|
31
|
+
:longitude => -73.141403,
|
|
32
|
+
:postal_code => nil,
|
|
33
|
+
:precision => :city,
|
|
34
|
+
:region => "NY",
|
|
35
|
+
:street => nil
|
|
36
|
+
)
|
|
37
|
+
assert_equal(location, @geocoder.locate('217 Union St., NY'))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
|
|
42
|
+
def prepare_response(id)
|
|
43
|
+
URI::HTTP.responses << response('mapquest', id)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class MetaCartaTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
URI::HTTP.responses = []
|
|
9
|
+
URI::HTTP.uris = []
|
|
10
|
+
|
|
11
|
+
@geocoder = MetaCarta.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_locate
|
|
15
|
+
prepare_response(:success)
|
|
16
|
+
|
|
17
|
+
expected = Location.new :latitude => 44.3939, :longitude => 33.3386
|
|
18
|
+
|
|
19
|
+
assert_equal expected, @geocoder.locate('baghdad')
|
|
20
|
+
assert_equal true, URI::HTTP.responses.empty?
|
|
21
|
+
assert_equal 1, URI::HTTP.uris.length
|
|
22
|
+
assert_equal 'http://labs.metacarta.com/GeoParser/?output=locations&q=baghdad',
|
|
23
|
+
URI::HTTP.uris.first
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_locate_bad_address
|
|
27
|
+
prepare_response(:bad_address)
|
|
28
|
+
assert_raises(AddressError) { @geocoder.locate('aoeueou') }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_locations
|
|
32
|
+
prepare_response(:multiple)
|
|
33
|
+
expected = Location.new :latitude => -122.33083, :longitude => 47.60639
|
|
34
|
+
assert_equal expected, @geocoder.locate('seattle')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
protected
|
|
38
|
+
def prepare_response(id = :success)
|
|
39
|
+
URI::HTTP.responses << response('meta_carta', id)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class MultiTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
@mock_geocoders = [mock("geocoder 1"), mock("geocoder 2")]
|
|
9
|
+
@mock_geocoders.each {|g| g.stubs(:locate) }
|
|
10
|
+
@geocoder = Multi.new(*@mock_geocoders)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_locate_calls_each_geocoder_and_raises_error
|
|
14
|
+
@mock_geocoders.each do |g|
|
|
15
|
+
g.expects(:locate).with('test').raises(Graticule::AddressError)
|
|
16
|
+
end
|
|
17
|
+
assert_raises(Graticule::AddressError) { @geocoder.locate 'test' }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_locate_returns_first_result_without_calling_others
|
|
21
|
+
result = mock("result")
|
|
22
|
+
@mock_geocoders.first.expects(:locate).returns(result)
|
|
23
|
+
@mock_geocoders.last.expects(:locate).never
|
|
24
|
+
assert_equal result, @geocoder.locate('test')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_locate_with_custom_block
|
|
28
|
+
@mock_geocoders.first.expects(:locate).returns(1)
|
|
29
|
+
@mock_geocoders.last.expects(:locate).returns(2)
|
|
30
|
+
@geocoder = Multi.new(*@mock_geocoders) {|r| r == 2 }
|
|
31
|
+
assert_equal 2, @geocoder.locate('test')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_locate_with_custom_block_and_no_match
|
|
35
|
+
@mock_geocoders.first.expects(:locate).returns(1)
|
|
36
|
+
@mock_geocoders.last.expects(:locate).returns(2)
|
|
37
|
+
@geocoder = Multi.new(*@mock_geocoders) {|r| r == 3 }
|
|
38
|
+
assert_raises(Graticule::AddressError) { @geocoder.locate('test') }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class MultimapTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
URI::HTTP.responses = []
|
|
9
|
+
URI::HTTP.uris = []
|
|
10
|
+
@geocoder = Multimap.new 'API_KEY'
|
|
11
|
+
@location = Location.new(
|
|
12
|
+
:street => "Oxford Street",
|
|
13
|
+
:locality => "London",
|
|
14
|
+
:postal_code => "W1",
|
|
15
|
+
:country => "GB",
|
|
16
|
+
:longitude => -0.14839,
|
|
17
|
+
:latitude => 51.51452,
|
|
18
|
+
:precision => :address
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_locate
|
|
23
|
+
prepare_response(:success)
|
|
24
|
+
assert_equal @location, @geocoder.locate('Oxford Street, LONDON, W1')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_url_from_string
|
|
28
|
+
prepare_response(:success)
|
|
29
|
+
@geocoder.locate('Oxford Street, LONDON, W1')
|
|
30
|
+
assert_equal 'http://clients.multimap.com/API/geocode/1.2/API_KEY?qs=Oxford%20Street,%20LONDON,%20W1', URI::HTTP.uris.first
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_url_from_location
|
|
34
|
+
prepare_response(:success)
|
|
35
|
+
@geocoder.locate(:street => 'Oxford Street', :city => 'London')
|
|
36
|
+
assert_equal 'http://clients.multimap.com/API/geocode/1.2/API_KEY?city=&countryCode=&postalCode=®ion=&street=Oxford%20Street', URI::HTTP.uris.first
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_locate_bad_address
|
|
41
|
+
prepare_response(:no_matches)
|
|
42
|
+
assert_raise(Error) { @geocoder.locate('yucksthoeusthaoeusnhtaosu') }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
protected
|
|
46
|
+
def prepare_response(id)
|
|
47
|
+
URI::HTTP.responses << response('multimap', id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# account code: INDIV30777
|
|
2
|
+
# license key: KG39-HM17-PZ95-NR98
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
4
|
+
|
|
5
|
+
module Graticule
|
|
6
|
+
module Geocoder
|
|
7
|
+
class PostcodeAnywhereTest < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
URI::HTTP.responses = []
|
|
11
|
+
URI::HTTP.uris = []
|
|
12
|
+
@geocoder = PostcodeAnywhere.new 'account_code', 'license_key'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_locate
|
|
16
|
+
prepare_response(:success)
|
|
17
|
+
location = Location.new(
|
|
18
|
+
:street => "204 Campbell Ave",
|
|
19
|
+
:locality => "Revelstoke",
|
|
20
|
+
:region => "BC",
|
|
21
|
+
:postal_code => "V0E",
|
|
22
|
+
:country => "Canada",
|
|
23
|
+
:longitude => -118.196970002204,
|
|
24
|
+
:latitude => 50.9997350418267
|
|
25
|
+
)
|
|
26
|
+
assert_equal location, @geocoder.locate(:street => "204 Campbell Ave",
|
|
27
|
+
:locality => "Revelstoke", :country => "Canada")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_locate_uk_address
|
|
31
|
+
prepare_response(:uk)
|
|
32
|
+
|
|
33
|
+
location = Location.new :latitude => 51.5728910186362, :longitude => -0.253788666693255
|
|
34
|
+
assert_equal location, @geocoder.locate(:street => '80 Wood Lane', :locality => 'London', :country => 'UK')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_empty
|
|
38
|
+
prepare_response(:empty)
|
|
39
|
+
|
|
40
|
+
assert_raises(Graticule::AddressError) { @geocoder.locate :street => 'foobar'}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
protected
|
|
44
|
+
def prepare_response(id)
|
|
45
|
+
URI::HTTP.responses << response('postcode_anywhere', id)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
module Geocoder
|
|
5
|
+
class YahooTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
URI::HTTP.responses = []
|
|
9
|
+
URI::HTTP.uris = []
|
|
10
|
+
@geocoder = Yahoo.new 'APP_ID'
|
|
11
|
+
@location = Location.new(
|
|
12
|
+
:street => "701 First Ave",
|
|
13
|
+
:locality => "Sunnyvale",
|
|
14
|
+
:region => "CA",
|
|
15
|
+
:postal_code => "94089-1019",
|
|
16
|
+
:country => "US",
|
|
17
|
+
:longitude => -122.024853,
|
|
18
|
+
:latitude => 37.416384,
|
|
19
|
+
:precision => :address
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_locate
|
|
24
|
+
prepare_response(:success)
|
|
25
|
+
assert_equal @location, @geocoder.locate('701 First Street, Sunnyvale, CA')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_url
|
|
29
|
+
prepare_response(:success)
|
|
30
|
+
@geocoder.locate('701 First Street, Sunnyvale, CA')
|
|
31
|
+
assert_equal 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=APP_ID&location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml',
|
|
32
|
+
URI::HTTP.uris.first
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_locate_bad_address
|
|
37
|
+
prepare_response(:unknown_address)
|
|
38
|
+
assert_raise(Error) { @geocoder.locate('yucksthoeusthaoeusnhtaosu') }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
protected
|
|
42
|
+
def prepare_response(id)
|
|
43
|
+
URI::HTTP.responses << response('yahoo', id)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
class GeocoderTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def test_bogus_service
|
|
7
|
+
assert_equal Geocoder::Bogus, Graticule.service(:bogus)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_yahoo_service
|
|
11
|
+
assert_equal Geocoder::Yahoo, Graticule.service(:yahoo)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_google_service
|
|
15
|
+
assert_equal Geocoder::Google, Graticule.service(:google)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_geocoder_us_service
|
|
19
|
+
assert_equal Geocoder::GeocoderUs, Graticule.service(:geocoder_us)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_meta_carta_service
|
|
23
|
+
assert_equal Geocoder::MetaCarta, Graticule.service(:meta_carta)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
2
|
+
|
|
3
|
+
module Graticule
|
|
4
|
+
class LocationTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@washington_dc = Location.new :latitude => 38.898748, :longitude => -77.037684,
|
|
8
|
+
:street => '1600 Pennsylvania Avenue, NW', :locality => 'Washington',
|
|
9
|
+
:region => 'DC', :postal_code => 20500, :country => 'US'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def test_distance_to
|
|
13
|
+
chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
|
|
14
|
+
assert_in_delta 594.820, @washington_dc.distance_to(chicago), 1.0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_responds_to
|
|
18
|
+
[:latitude, :longitude, :street, :locality, :region, :postal_code, :country, :coordinates, :precision].each do |m|
|
|
19
|
+
assert Location.new.respond_to?(m), "should respond to #{m}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_coordinates
|
|
24
|
+
l = Location.new(:latitude => 100, :longitude => 50)
|
|
25
|
+
assert_equal [100, 50], l.coordinates
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_equal
|
|
29
|
+
assert_equal Location.new, Location.new
|
|
30
|
+
|
|
31
|
+
attrs = {:latitude => 100.5389, :longitude => -147.5893, :street => '123 A Street',
|
|
32
|
+
:locality => 'Somewhere', :region => 'NO', :postal_code => '12345', :country => 'USA'}
|
|
33
|
+
|
|
34
|
+
assert_equal Location.new(attrs), Location.new(attrs)
|
|
35
|
+
attrs.each do |k,v|
|
|
36
|
+
assert_equal Location.new(k => v), Location.new(k => v)
|
|
37
|
+
assert_not_equal Location.new, Location.new(k => v)
|
|
38
|
+
assert_not_equal Location.new(attrs), Location.new(attrs.update(k => nil))
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_antipode
|
|
43
|
+
chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
|
|
44
|
+
|
|
45
|
+
assert_equal [-38.898748, 102.962316], @washington_dc.antipode.coordinates
|
|
46
|
+
assert_equal [-41.85, 92.35], chicago.antipode.coordinates
|
|
47
|
+
assert_equal [-41, -180], Graticule::Location.new(:latitude => 41, :longitude => 0).antipode.coordinates
|
|
48
|
+
assert_equal [-41, 179], Graticule::Location.new(:latitude => 41, :longitude => -1).antipode.coordinates
|
|
49
|
+
assert_equal [-41, -179], Graticule::Location.new(:latitude => 41, :longitude => 1).antipode.coordinates
|
|
50
|
+
|
|
51
|
+
assert_equal @washington_dc.coordinates, @washington_dc.antipode.antipode.coordinates
|
|
52
|
+
assert_equal chicago.coordinates, chicago.antipode.antipode.coordinates
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_to_s
|
|
56
|
+
assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500 US",
|
|
57
|
+
@washington_dc.to_s
|
|
58
|
+
assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500",
|
|
59
|
+
@washington_dc.to_s(:country => false)
|
|
60
|
+
assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500",
|
|
61
|
+
@washington_dc.to_s(:country => false)
|
|
62
|
+
assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500\nlatitude: 38.898748, longitude: -77.037684",
|
|
63
|
+
@washington_dc.to_s(:country => false, :coordinates => true)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_new_from_s
|
|
67
|
+
assert_equal Location.new(:longitude => 14.40046, :latitude => 50.10174),
|
|
68
|
+
Location.new(:latitude => %{50°6'6.246"N}, :longitude => %{14°24'1.648"E})
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_blank?
|
|
73
|
+
assert Location.new.blank?
|
|
74
|
+
[:latitude, :longitude, :street, :locality, :region, :postal_code, :country].each do |attr|
|
|
75
|
+
assert !Location.new(attr => 'Foo').blank?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|