geokit 1.8.5 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +7 -0
  4. data/README.markdown +31 -14
  5. data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
  6. data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
  7. data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
  8. data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
  9. data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
  10. data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
  11. data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
  12. data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
  13. data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
  14. data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
  15. data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
  16. data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
  17. data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
  18. data/geokit.gemspec +5 -3
  19. data/lib/geokit/bounds.rb +40 -31
  20. data/lib/geokit/core_ext.rb +1 -1
  21. data/lib/geokit/geo_loc.rb +63 -41
  22. data/lib/geokit/geocoders.rb +13 -13
  23. data/lib/geokit/geocoders/bing.rb +9 -9
  24. data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
  25. data/lib/geokit/geocoders/fcc.rb +4 -4
  26. data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
  27. data/lib/geokit/geocoders/geo_plugin.rb +5 -6
  28. data/lib/geokit/geocoders/geocodio.rb +2 -2
  29. data/lib/geokit/geocoders/geonames.rb +18 -12
  30. data/lib/geokit/geocoders/google.rb +31 -30
  31. data/lib/geokit/geocoders/ip.rb +3 -4
  32. data/lib/geokit/geocoders/mapbox.rb +94 -0
  33. data/lib/geokit/geocoders/mapquest.rb +5 -5
  34. data/lib/geokit/geocoders/opencage.rb +93 -0
  35. data/lib/geokit/geocoders/openstreetmap.rb +9 -6
  36. data/lib/geokit/geocoders/ripe.rb +3 -3
  37. data/lib/geokit/geocoders/us_geocoder.rb +10 -9
  38. data/lib/geokit/geocoders/yahoo.rb +33 -34
  39. data/lib/geokit/geocoders/yandex.rb +17 -17
  40. data/lib/geokit/inflectors.rb +4 -10
  41. data/lib/geokit/lat_lng.rb +50 -26
  42. data/lib/geokit/mappable.rb +83 -83
  43. data/lib/geokit/multi_geocoder.rb +25 -20
  44. data/lib/geokit/net_adapter/net_http.rb +7 -4
  45. data/lib/geokit/polygon.rb +36 -4
  46. data/lib/geokit/version.rb +1 -1
  47. data/test/helper.rb +15 -13
  48. data/test/test_base_geocoder.rb +6 -7
  49. data/test/test_bing_geocoder.rb +20 -21
  50. data/test/test_bounds.rb +26 -28
  51. data/test/test_ca_geocoder.rb +9 -10
  52. data/test/test_fcc_geocoder.rb +1 -1
  53. data/test/test_free_geo_ip_geocoder.rb +1 -1
  54. data/test/test_geo_plugin_geocoder.rb +9 -9
  55. data/test/test_geoloc.rb +7 -6
  56. data/test/test_geonames_geocoder.rb +28 -6
  57. data/test/test_google_geocoder.rb +210 -176
  58. data/test/test_inflector.rb +0 -1
  59. data/test/test_ipgeocoder.rb +17 -18
  60. data/test/test_latlng.rb +105 -85
  61. data/test/test_map_quest.rb +18 -21
  62. data/test/test_mapbox_geocoder.rb +31 -0
  63. data/test/test_mappable.rb +46 -0
  64. data/test/test_maxmind_geocoder.rb +1 -3
  65. data/test/test_multi_geocoder.rb +8 -9
  66. data/test/test_multi_ip_geocoder.rb +3 -5
  67. data/test/test_net_adapter.rb +4 -4
  68. data/test/test_opencage_geocoder.rb +108 -0
  69. data/test/test_openstreetmap_geocoder.rb +62 -44
  70. data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
  71. data/test/test_ripe_geocoder.rb +2 -0
  72. data/test/test_us_geocoder.rb +7 -8
  73. data/test/test_yahoo_geocoder.rb +20 -21
  74. data/test/test_yandex_geocoder.rb +34 -35
  75. metadata +79 -56
  76. data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +0 -401
@@ -2,7 +2,6 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class InflectorTest < Test::Unit::TestCase #:nodoc: all
5
-
6
5
  def test_titleize
7
6
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar Grove')
8
7
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar grove')
@@ -2,29 +2,28 @@
2
2
  require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
-
6
- IP_FAILURE=<<-EOF
5
+ IP_FAILURE = <<-EOF
7
6
  Country: SWITZERLAND (CH)
8
7
  City: (Unknown City)
9
8
  Latitude:
10
9
  Longitude:
11
10
  EOF
12
11
 
13
- IP_SUCCESS=<<-EOF
12
+ IP_SUCCESS = <<-EOF
14
13
  Country: UNITED STATES (US)
15
14
  City: Sugar Grove, IL
16
15
  Latitude: 41.7696
17
16
  Longitude: -88.4588
18
17
  EOF
19
18
 
20
- IP_LATIN=<<-EOF
19
+ IP_LATIN = <<-EOF
21
20
  Country: BRAZIL (BR)
22
21
  City: S\xE3o Jos\xE9 do Rio Pr\xEAto\n
23
22
  Latitude: -20.8
24
23
  Longitude: -49.3833
25
24
  EOF
26
25
 
27
- IP_UNICODED=<<-EOF
26
+ IP_UNICODED = <<-EOF
28
27
  Country: SWEDEN (SE)
29
28
  City: Borås
30
29
  Latitude: 57.7167
@@ -45,7 +44,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
45
44
 
46
45
  def setup
47
46
  super
48
- @success.provider = "ip"
47
+ @success.provider = 'ip'
49
48
  end
50
49
 
51
50
  def test_successful_lookup
@@ -57,10 +56,10 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
57
56
  assert_not_nil location
58
57
  assert_equal 41.7696, location.lat
59
58
  assert_equal(-88.4588, location.lng)
60
- assert_equal "Sugar Grove", location.city
61
- assert_equal "IL", location.state
62
- assert_equal "US", location.country_code
63
- assert_equal "ip", location.provider
59
+ assert_equal 'Sugar Grove', location.city
60
+ assert_equal 'IL', location.state
61
+ assert_equal 'US', location.country_code
62
+ assert_equal 'ip', location.provider
64
63
  assert location.success?
65
64
  end
66
65
 
@@ -75,8 +74,8 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
75
74
  assert_equal 12.9167, location.lng
76
75
  assert_equal "Bor\303\245s", location.city
77
76
  assert_nil location.state
78
- assert_equal "SE", location.country_code
79
- assert_equal "ip", location.provider
77
+ assert_equal 'SE', location.country_code
78
+ assert_equal 'ip', location.provider
80
79
  assert location.success?
81
80
  end
82
81
 
@@ -90,10 +89,10 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
90
89
  assert_not_nil location
91
90
  assert_equal -20.8, location.lat
92
91
  assert_equal -49.3833, location.lng
93
- assert_equal "São José Do Rio Prêto", location.city
92
+ assert_equal 'São José Do Rio Prêto', location.city
94
93
  assert_nil location.state
95
- assert_equal "BR", location.country_code
96
- assert_equal "ip", location.provider
94
+ assert_equal 'BR', location.country_code
95
+ assert_equal 'ip', location.provider
97
96
  assert location.success?
98
97
  end
99
98
 
@@ -102,7 +101,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
102
101
  failure.expects(:body).returns(IP_FAILURE)
103
102
  url = 'http://api.hostip.info/get_html.php?ip=128.178.0.0&position=true'
104
103
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
105
- location = Geokit::Geocoders::IpGeocoder.geocode("128.178.0.0")
104
+ location = Geokit::Geocoders::IpGeocoder.geocode('128.178.0.0')
106
105
  assert_not_nil location
107
106
  assert !location.success?
108
107
  end
@@ -118,7 +117,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
118
117
 
119
118
  def test_invalid_ip
120
119
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
121
- location = Geokit::Geocoders::IpGeocoder.geocode("blah")
120
+ location = Geokit::Geocoders::IpGeocoder.geocode('blah')
122
121
  assert_not_nil location
123
122
  assert !location.success?
124
123
  end
@@ -127,7 +126,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
127
126
  failure = MockFailure.new
128
127
  url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
129
128
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
130
- location = Geokit::Geocoders::IpGeocoder.geocode("12.215.42.19")
129
+ location = Geokit::Geocoders::IpGeocoder.geocode('12.215.42.19')
131
130
  assert_not_nil location
132
131
  assert !location.success?
133
132
  end
@@ -1,65 +1,80 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class LatLngTest < Test::Unit::TestCase #:nodoc: all
4
-
5
4
  def setup
6
- @loc_a = Geokit::LatLng.new(32.918593,-96.958444)
7
- @loc_e = Geokit::LatLng.new(32.969527,-96.990159)
5
+ @loc_a = Geokit::LatLng.new(32.918593, -96.958444)
6
+ @loc_e = Geokit::LatLng.new(32.969527, -96.990159)
8
7
  @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
9
8
  end
10
9
 
11
10
  def valid_reverse_geocoding_result
12
11
  location = Geokit::GeoLoc.new({
13
- :city => "Essen",
14
- :country_code => "DE",
15
- :lat => 51.4578329,
16
- :lng => 7.0166848,
17
- :provider => "google",
18
- :state => "Nordrhein-Westfalen",
19
- :street_address => "Porscheplatz 1",
20
- :zip => "45127"
12
+ city: 'Essen',
13
+ country_code: 'DE',
14
+ lat: 51.4578329,
15
+ lng: 7.0166848,
16
+ provider: 'google',
17
+ state: 'Nordrhein-Westfalen',
18
+ street_address: 'Porscheplatz 1',
19
+ zip: '45127'
21
20
  })
22
21
 
23
- location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
22
+ location.full_address = 'Porscheplatz 1, 45127 Essen, Deutschland'
24
23
  location.precision = 'address'
25
24
  location.provider = 'google'
26
25
  location.success = true
27
26
  location
28
27
  end
29
28
 
29
+ def test_existance_of_latitude_alias
30
+ assert_respond_to(@loc_a, :latitude)
31
+ end
32
+
33
+ def test_existance_of_longitude_alias
34
+ assert_respond_to(@loc_a, :longitude)
35
+ end
36
+
37
+ def test_that_lat_and_latitude_are_same_object
38
+ assert_same(@loc_a.lat, @loc_a.latitude)
39
+ end
40
+
41
+ def test_that_lng_and_longitude_are_same_object
42
+ assert_same(@loc_a.lng, @loc_a.longitude)
43
+ end
44
+
30
45
  def test_distance_between_same_using_defaults
31
46
  assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
32
47
  assert_equal 0, @loc_a.distance_to(@loc_a)
33
48
  end
34
49
 
35
50
  def test_distance_between_same_with_miles_and_flat
36
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
37
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
51
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :miles, formula: :flat)
52
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :miles, formula: :flat)
38
53
  end
39
54
 
40
55
  def test_distance_between_same_with_kms_and_flat
41
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
42
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
56
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :kms, formula: :flat)
57
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :kms, formula: :flat)
43
58
  end
44
59
 
45
60
  def test_distance_between_same_with_nms_and_flat
46
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
47
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
61
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :nms, formula: :flat)
62
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :nms, formula: :flat)
48
63
  end
49
64
 
50
65
  def test_distance_between_same_with_miles_and_sphere
51
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
52
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
66
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :miles, formula: :sphere)
67
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :miles, formula: :sphere)
53
68
  end
54
69
 
55
70
  def test_distance_between_same_with_kms_and_sphere
56
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
57
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
71
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :kms, formula: :sphere)
72
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :kms, formula: :sphere)
58
73
  end
59
74
 
60
75
  def test_distance_between_same_with_nms_and_sphere
61
- assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
62
- assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
76
+ assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, units: :nms, formula: :sphere)
77
+ assert_equal 0, @loc_a.distance_to(@loc_a, units: :nms, formula: :sphere)
63
78
  end
64
79
 
65
80
  def test_distance_between_diff_using_defaults
@@ -68,46 +83,51 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
68
83
  end
69
84
 
70
85
  def test_distance_between_diff_with_miles_and_flat
71
- assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
72
- assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
86
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :miles, formula: :flat), 0.2
87
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, units: :miles, formula: :flat), 0.2
73
88
  end
74
89
 
75
90
  def test_distance_between_diff_with_kms_and_flat
76
- assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
77
- assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
91
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :kms, formula: :flat), 0.4
92
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, units: :kms, formula: :flat), 0.4
93
+ end
94
+
95
+ def test_distance_between_diff_with_meters_and_flat
96
+ assert_in_delta 6390, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :meters, formula: :flat), 2
97
+ assert_in_delta 6390, @loc_a.distance_to(@loc_e, units: :meters, formula: :flat), 2
78
98
  end
79
99
 
80
100
  def test_distance_between_diff_with_nms_and_flat
81
- assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
82
- assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
101
+ assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :nms, formula: :flat), 0.4
102
+ assert_in_delta 3.334, @loc_a.distance_to(@loc_e, units: :nms, formula: :flat), 0.4
83
103
  end
84
104
 
85
105
  def test_distance_between_diff_with_miles_and_sphere
86
- assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
87
- assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
106
+ assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :miles, formula: :sphere), 0.01
107
+ assert_in_delta 3.97, @loc_a.distance_to(@loc_e, units: :miles, formula: :sphere), 0.01
88
108
  end
89
109
 
90
110
  def test_distance_between_diff_with_kms_and_sphere
91
- assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
92
- assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
111
+ assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :kms, formula: :sphere), 0.01
112
+ assert_in_delta 6.39, @loc_a.distance_to(@loc_e, units: :kms, formula: :sphere), 0.01
93
113
  end
94
114
 
95
115
  def test_distance_between_diff_with_nms_and_sphere
96
- assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
97
- assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
116
+ assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, units: :nms, formula: :sphere), 0.01
117
+ assert_in_delta 3.454, @loc_a.distance_to(@loc_e, units: :nms, formula: :sphere), 0.01
98
118
  end
99
119
 
100
120
  def test_manually_mixed_in
101
121
  assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
102
122
  assert_equal 0, @point.distance_to(@point)
103
123
  assert_equal 0, @point.distance_to(@loc_a)
104
- assert_in_delta 3.97, @point.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
105
- assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
106
- assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
124
+ assert_in_delta 3.97, @point.distance_to(@loc_e, units: :miles, formula: :flat), 0.2
125
+ assert_in_delta 6.39, @point.distance_to(@loc_e, units: :kms, formula: :flat), 0.4
126
+ assert_in_delta 3.334, @point.distance_to(@loc_e, units: :nms, formula: :flat), 0.4
107
127
  end
108
128
 
109
129
  def test_heading_between
110
- assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
130
+ assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a, @loc_e), 0.5
111
131
  end
112
132
 
113
133
  def test_heading_to
@@ -115,65 +135,65 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
115
135
  end
116
136
 
117
137
  def test_class_endpoint
118
- endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
138
+ endpoint = Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
119
139
  assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
120
140
  assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
121
141
  end
122
142
 
123
143
  def test_instance_endpoint
124
- endpoint=@loc_a.endpoint(332, 3.97)
144
+ endpoint = @loc_a.endpoint(332, 3.97)
125
145
  assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
126
146
  assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
127
147
  end
128
148
 
129
149
  def test_midpoint
130
- midpoint=@loc_a.midpoint_to(@loc_e)
150
+ midpoint = @loc_a.midpoint_to(@loc_e)
131
151
  assert_in_delta 32.944061, midpoint.lat, 0.0005
132
152
  assert_in_delta(-96.974296, midpoint.lng, 0.0005)
133
153
  end
134
154
 
135
155
  def test_normalize
136
- lat=37.7690
137
- lng=-122.443
138
- res=Geokit::LatLng.normalize(lat,lng)
139
- assert_equal res,Geokit::LatLng.new(lat,lng)
140
- res=Geokit::LatLng.normalize("#{lat}, #{lng}")
141
- assert_equal res,Geokit::LatLng.new(lat,lng)
142
- res=Geokit::LatLng.normalize("#{lat} #{lng}")
143
- assert_equal res,Geokit::LatLng.new(lat,lng)
144
- res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
145
- assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
146
- res=Geokit::LatLng.normalize([lat,lng])
147
- assert_equal res,Geokit::LatLng.new(lat,lng)
156
+ lat = 37.7690
157
+ lng = -122.443
158
+ res = Geokit::LatLng.normalize(lat, lng)
159
+ assert_equal res, Geokit::LatLng.new(lat, lng)
160
+ res = Geokit::LatLng.normalize("#{lat}, #{lng}")
161
+ assert_equal res, Geokit::LatLng.new(lat, lng)
162
+ res = Geokit::LatLng.normalize("#{lat} #{lng}")
163
+ assert_equal res, Geokit::LatLng.new(lat, lng)
164
+ res = Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
165
+ assert_equal res, Geokit::LatLng.new(lat.to_i, lng.to_i)
166
+ res = Geokit::LatLng.normalize([lat, lng])
167
+ assert_equal res, Geokit::LatLng.new(lat, lng)
148
168
  end
149
169
 
150
170
  def test_hash
151
- lat=37.7690
152
- lng=-122.443
153
- first = Geokit::LatLng.new(lat,lng)
154
- second = Geokit::LatLng.new(lat,lng)
171
+ lat = 37.7690
172
+ lng = -122.443
173
+ first = Geokit::LatLng.new(lat, lng)
174
+ second = Geokit::LatLng.new(lat, lng)
155
175
  assert_equal first.hash, second.hash
156
176
  end
157
177
 
158
178
  def test_eql?
159
- lat=37.7690
160
- lng=-122.443
161
- first = Geokit::LatLng.new(lat,lng)
162
- second = Geokit::LatLng.new(lat,lng)
179
+ lat = 37.7690
180
+ lng = -122.443
181
+ first = Geokit::LatLng.new(lat, lng)
182
+ second = Geokit::LatLng.new(lat, lng)
163
183
  assert first.eql?(second)
164
184
  assert second.eql?(first)
165
185
  end
166
186
 
167
187
  def test_valid_when_lat_and_lng_defined
168
- assert Geokit::LatLng.new(37.7690,-122.443).valid?
188
+ assert Geokit::LatLng.new(37.7690, -122.443).valid?
169
189
  end
170
190
 
171
191
  def test_not_valid_when_lat_is_nil
172
- assert ! Geokit::LatLng.new(nil,-122.443).valid?
192
+ assert ! Geokit::LatLng.new(nil, -122.443).valid?
173
193
  end
174
194
 
175
195
  def test_not_valid_when_lng_is_nil
176
- assert ! Geokit::LatLng.new(37.7690,nil).valid?
196
+ assert ! Geokit::LatLng.new(37.7690, nil).valid?
177
197
  end
178
198
 
179
199
  def test_reverse_geocode
@@ -181,40 +201,40 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
181
201
  Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
182
202
  res = point.reverse_geocode
183
203
 
184
- assert_equal "Nordrhein-Westfalen", res.state
185
- assert_equal "Essen", res.city
186
- assert_equal "45127", res.zip
187
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
204
+ assert_equal 'Nordrhein-Westfalen', res.state
205
+ assert_equal 'Essen', res.city
206
+ assert_equal '45127', res.zip
207
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
188
208
  assert res.is_us? == false
189
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
209
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
190
210
  end
191
211
 
192
212
  def test_reverse_geocoding_using_specific_geocoder
193
213
  point = Geokit::LatLng.new(51.4578329, 7.0166848)
194
214
  Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
195
- res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder)
215
+ res = point.reverse_geocode(using: Geokit::Geocoders::GoogleGeocoder)
196
216
 
197
- assert_equal "Nordrhein-Westfalen", res.state
198
- assert_equal "Essen", res.city
199
- assert_equal "45127", res.zip
200
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
217
+ assert_equal 'Nordrhein-Westfalen', res.state
218
+ assert_equal 'Essen', res.city
219
+ assert_equal '45127', res.zip
220
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
201
221
  assert res.is_us? == false
202
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
203
- assert_equal "google", res.provider
222
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
223
+ assert_equal 'google', res.provider
204
224
  end
205
225
 
206
226
  def test_reverse_geocoding_using_specific_geocoder_short_syntax
207
227
  point = Geokit::LatLng.new(51.4578329, 7.0166848)
208
228
  Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
209
- res = point.reverse_geocode(:using => :google)
229
+ res = point.reverse_geocode(using: :google)
210
230
 
211
- assert_equal "Nordrhein-Westfalen", res.state
212
- assert_equal "Essen", res.city
213
- assert_equal "45127", res.zip
214
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
231
+ assert_equal 'Nordrhein-Westfalen', res.state
232
+ assert_equal 'Essen', res.city
233
+ assert_equal '45127', res.zip
234
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
215
235
  assert res.is_us? == false
216
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
217
- assert_equal "google", res.provider
236
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
237
+ assert_equal 'google', res.provider
218
238
  end
219
239
 
220
240
  def test_to_dms
@@ -1,55 +1,52 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class MapQuestGeocoderTest < BaseGeocoderTest #:nodoc: all
4
-
5
4
  def setup
6
5
  super
7
6
  @full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
8
- @google_full_hash = {:street_address=>"100 Spear St Apt. 5", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
9
- @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
7
+ @google_full_hash = {street_address: '100 Spear St Apt. 5', city: 'San Francisco', state: 'CA', zip: '94105', country_code: 'US'}
8
+ @google_city_hash = {city: 'San Francisco', state: 'CA'}
10
9
 
11
10
  @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
12
11
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
13
12
  end
14
13
 
15
-
16
14
  def test_map_quest_full_address_with_geo_loc
17
15
  VCR.use_cassette('map_quest_full') do
18
- key = 'Fmjtd%7Cluur2d0125%2C2s%3Do5-9a8lhz'
19
- Geokit::Geocoders::MapQuestGeocoder.key =key
16
+ key = 'Fmjtd%7Cluur2d0125%2C2s%3Do5-9a8lhz'
17
+ Geokit::Geocoders::MapQuestGeocoder.key = key
20
18
  url = "https://www.mapquestapi.com/geocoding/v1/address?key=#{key}&location=100+Spear+St+Apt.+5%2C+San+Francisco%2C+CA%2C+94105%2C+US"
21
19
  TestHelper.expects(:last_url).with(url)
22
- res=Geokit::Geocoders::MapQuestGeocoder.geocode(@google_full_loc)
23
- assert_equal "CA", res.state
24
- assert_equal "San Francisco", res.city
20
+ res = Geokit::Geocoders::MapQuestGeocoder.geocode(@google_full_loc)
21
+ assert_equal 'CA', res.state
22
+ assert_equal 'San Francisco', res.city
25
23
  assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
26
24
  assert res.is_us?
27
- assert_equal "100 Spear St, Apt 5, San Francisco, CA, 94105-1500, US", res.full_address #slightly different from yahoo
28
- assert_equal "map_quest", res.provider
25
+ assert_equal '100 Spear St, Apt 5, San Francisco, CA, 94105-1500, US', res.full_address # slightly different from yahoo
26
+ assert_equal 'map_quest', res.provider
29
27
  end
30
28
  end
31
29
 
32
-
33
30
  def test_reverse_geocode
34
31
  VCR.use_cassette('map_quest_reverse_madrid') do
35
- madrid = Geokit::GeoLoc.new
36
- madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
32
+ madrid = Geokit::GeoLoc.new
33
+ madrid.lat, madrid.lng = '40.4167413', '-3.7032498'
37
34
  key = 'Fmjtd%7Cluur2d0125%2C2s%3Do5-9a8lhz'
38
- Geokit::Geocoders::MapQuestGeocoder.key =key
35
+ Geokit::Geocoders::MapQuestGeocoder.key = key
39
36
  url = "https://www.mapquestapi.com/geocoding/v1/reverse?key=#{key}&location=#{madrid.lat},#{madrid.lng}"
40
37
  TestHelper.expects(:last_url).with(url)
41
- res=Geokit::Geocoders::MapQuestGeocoder.do_reverse_geocode(madrid.ll)
38
+ res = Geokit::Geocoders::MapQuestGeocoder.do_reverse_geocode(madrid.ll)
42
39
 
43
40
  assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
44
41
  assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
45
- assert_equal "ES", res.country_code
46
- assert_equal "map_quest", res.provider
42
+ assert_equal 'ES', res.country_code
43
+ assert_equal 'map_quest', res.provider
47
44
 
48
- assert_equal "Madrid", res.city
49
- assert_equal "Comunidad de Madrid", res.state
45
+ assert_equal 'Madrid', res.city
46
+ assert_equal 'Comunidad de Madrid', res.state
50
47
 
51
48
  assert_equal nil, res.country
52
- assert_equal "28014", res.zip
49
+ assert_equal '28014', res.zip
53
50
  assert_equal true, res.success
54
51
  end
55
52
  end