geocoder 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

@@ -34,13 +34,13 @@ class GeocoderTest < Test::Unit::TestCase
34
34
  def test_distance_to_returns_float
35
35
  v = Venue.new(*venue_params(:msg))
36
36
  v.latitude, v.longitude = [40.750354, -73.993371]
37
- assert (d = v.distance_to(30, -94)).is_a?(Float)
37
+ assert (d = v.distance_to([30, -94])).is_a?(Float)
38
38
  end
39
39
 
40
40
  def test_distance_from_is_alias_for_distance_to
41
41
  v = Venue.new(*venue_params(:msg))
42
42
  v.latitude, v.longitude = [40.750354, -73.993371]
43
- assert_equal v.distance_from(30, -94), v.distance_to(30, -94)
43
+ assert_equal v.distance_from([30, -94]), v.distance_to([30, -94])
44
44
  end
45
45
 
46
46
  def test_coordinates_method
@@ -48,7 +48,15 @@ class GeocoderTest < Test::Unit::TestCase
48
48
  end
49
49
 
50
50
  def test_address_method
51
- assert Geocoder.address(40.750354, -73.993371).is_a?(String)
51
+ assert Geocoder.address([40.750354, -73.993371]).is_a?(String)
52
+ end
53
+
54
+ def test_geographic_center_doesnt_overwrite_argument_value
55
+ # this tests for the presence of a bug that was introduced in version 0.9.11
56
+ orig_points = [[52,8], [46,9], [42,5]]
57
+ points = orig_points.clone
58
+ Geocoder::Calculations.geographic_center(points)
59
+ assert_equal orig_points, points
52
60
  end
53
61
 
54
62
 
@@ -131,13 +139,13 @@ class GeocoderTest < Test::Unit::TestCase
131
139
  def test_result_has_required_attributes
132
140
  all_lookups.each do |l|
133
141
  Geocoder::Configuration.lookup = l
134
- result = Geocoder.search(45.423733, -75.676333).first
142
+ result = Geocoder.search([45.423733, -75.676333]).first
135
143
  assert_result_has_required_attributes(result)
136
144
  end
137
145
  end
138
146
 
139
147
 
140
- # --- calcluations ---
148
+ # --- calculations: degree distance ---
141
149
 
142
150
  def test_longitude_degree_distance_at_equator
143
151
  assert_equal 69, Geocoder::Calculations.longitude_degree_distance(0).round
@@ -151,18 +159,24 @@ class GeocoderTest < Test::Unit::TestCase
151
159
  assert_equal 0, Geocoder::Calculations.longitude_degree_distance(89.98).round
152
160
  end
153
161
 
162
+
163
+ # --- calculations: distance between ---
164
+
154
165
  def test_distance_between_in_miles
155
- assert_equal 69, Geocoder::Calculations.distance_between(0,0, 0,1).round
156
- la_to_ny = Geocoder::Calculations.distance_between(34.05,-118.25, 40.72,-74).round
166
+ assert_equal 69, Geocoder::Calculations.distance_between([0,0], [0,1]).round
167
+ la_to_ny = Geocoder::Calculations.distance_between([34.05,-118.25], [40.72,-74]).round
157
168
  assert (la_to_ny - 2444).abs < 10
158
169
  end
159
170
 
160
171
  def test_distance_between_in_kilometers
161
- assert_equal 111, Geocoder::Calculations.distance_between(0,0, 0,1, :units => :km).round
162
- la_to_ny = Geocoder::Calculations.distance_between(34.05,-118.25, 40.72,-74, :units => :km).round
172
+ assert_equal 111, Geocoder::Calculations.distance_between([0,0], [0,1], :units => :km).round
173
+ la_to_ny = Geocoder::Calculations.distance_between([34.05,-118.25], [40.72,-74], :units => :km).round
163
174
  assert (la_to_ny - 3942).abs < 10
164
175
  end
165
176
 
177
+
178
+ # --- calculations: geographic center ---
179
+
166
180
  def test_geographic_center_with_arrays
167
181
  assert_equal [0.0, 0.5],
168
182
  Geocoder::Calculations.geographic_center([[0,0], [0,1]])
@@ -176,6 +190,9 @@ class GeocoderTest < Test::Unit::TestCase
176
190
  assert_equal [0.0, 0.5], Geocoder::Calculations.geographic_center([p1, p2])
177
191
  end
178
192
 
193
+
194
+ # --- calculations: bounding box ---
195
+
179
196
  def test_bounding_box_calculation_in_miles
180
197
  center = [51, 7] # Cologne, DE
181
198
  radius = 10 # miles
@@ -183,7 +200,7 @@ class GeocoderTest < Test::Unit::TestCase
183
200
  dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0])
184
201
  corners = [50.86, 6.77, 51.14, 7.23]
185
202
  assert_equal corners.map{ |i| (i * 100).round },
186
- Geocoder::Calculations.bounding_box(center[0], center[1], radius).map{ |i| (i * 100).round }
203
+ Geocoder::Calculations.bounding_box(center, radius).map{ |i| (i * 100).round }
187
204
  end
188
205
 
189
206
  def test_bounding_box_calculation_in_kilometers
@@ -193,11 +210,28 @@ class GeocoderTest < Test::Unit::TestCase
193
210
  dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0], :km)
194
211
  corners = [50, 5.41, 52, 8.59]
195
212
  assert_equal corners.map{ |i| (i * 100).round },
196
- Geocoder::Calculations.bounding_box(center[0], center[1], radius, :units => :km).map{ |i| (i * 100).round }
213
+ Geocoder::Calculations.bounding_box(center, radius, :units => :km).map{ |i| (i * 100).round }
197
214
  end
198
215
 
216
+ def test_bounding_box_calculation_with_object
217
+ center = [51, 7] # Cologne, DE
218
+ radius = 10 # miles
219
+ dlon = radius / Geocoder::Calculations.latitude_degree_distance
220
+ dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0])
221
+ corners = [50.86, 6.77, 51.14, 7.23]
222
+ obj = Landmark.new("Cologne", center[0], center[1])
223
+ assert_equal corners.map{ |i| (i * 100).round },
224
+ Geocoder::Calculations.bounding_box(obj, radius).map{ |i| (i * 100).round }
225
+ end
199
226
 
200
- # --- bearing ---
227
+ def test_bounding_box_calculation_with_address_string
228
+ assert_nothing_raised do
229
+ Geocoder::Calculations.bounding_box("4893 Clay St, San Francisco, CA", 50)
230
+ end
231
+ end
232
+
233
+
234
+ # --- calculations: bearing ---
201
235
 
202
236
  def test_compass_points
203
237
  assert_equal "N", Geocoder::Calculations.compass_point(0)
@@ -229,17 +263,29 @@ class GeocoderTest < Test::Unit::TestCase
229
263
  methods.each do |m|
230
264
  directions.each_with_index do |d,i|
231
265
  opp = directions[(i + 2) % 4] # opposite direction
232
- p1 = points[d]
233
- p2 = points[opp]
234
-
235
- args = p1 + p2 + [:method => m]
236
- b = Geocoder::Calculations.bearing_between(*args)
266
+ b = Geocoder::Calculations.bearing_between(
267
+ points[d], points[opp], :method => m)
237
268
  assert (b - bearings[opp]).abs < 1,
238
269
  "Bearing (#{m}) should be close to #{bearings[opp]} but was #{b}."
239
270
  end
240
271
  end
241
272
  end
242
273
 
274
+ def test_spherical_bearing_to
275
+ l = Landmark.new(*landmark_params(:msg))
276
+ assert_equal 324, l.bearing_to([50,-85], :method => :spherical).round
277
+ end
278
+
279
+ def test_spherical_bearing_from
280
+ l = Landmark.new(*landmark_params(:msg))
281
+ assert_equal 136, l.bearing_from([50,-85], :method => :spherical).round
282
+ end
283
+
284
+ def test_linear_bearing_from_and_to_are_exactly_opposite
285
+ l = Landmark.new(*landmark_params(:msg))
286
+ assert_equal l.bearing_from([50,-86.1]), l.bearing_to([50,-86.1]) - 180
287
+ end
288
+
243
289
 
244
290
  # --- input handling ---
245
291
 
@@ -258,6 +304,13 @@ class GeocoderTest < Test::Unit::TestCase
258
304
  assert !Geocoder.send(:blank_query?, "Москва") # no ASCII characters
259
305
  end
260
306
 
307
+ def test_coordinates_detection
308
+ lookup = Geocoder::Lookup::Google.new
309
+ assert lookup.send(:coordinates?, "51.178844,5")
310
+ assert lookup.send(:coordinates?, "51.178844, -1.826189")
311
+ assert !lookup.send(:coordinates?, "232.65.123")
312
+ end
313
+
261
314
  def test_does_not_choke_on_nil_address
262
315
  all_lookups.each do |l|
263
316
  Geocoder::Configuration.lookup = l
@@ -265,6 +318,13 @@ class GeocoderTest < Test::Unit::TestCase
265
318
  end
266
319
  end
267
320
 
321
+ def test_extract_coordinates
322
+ coords = [-23,47]
323
+ l = Landmark.new("Madagascar", coords[0], coords[1])
324
+ assert_equal coords, Geocoder::Calculations.extract_coordinates(l)
325
+ assert_equal coords, Geocoder::Calculations.extract_coordinates(coords)
326
+ end
327
+
268
328
 
269
329
  # --- error handling ---
270
330
 
@@ -313,7 +373,7 @@ class GeocoderTest < Test::Unit::TestCase
313
373
 
314
374
  def test_geocoder_ca_result_components
315
375
  Geocoder::Configuration.lookup = :geocoder_ca
316
- result = Geocoder.search(45.423733, -75.676333).first
376
+ result = Geocoder.search([45.423733, -75.676333]).first
317
377
  assert_equal "CA", result.country_code
318
378
  assert_equal "289 Somerset ST E, Ottawa, ON K1N6W1, Canada", result.address
319
379
  end
@@ -351,13 +411,6 @@ class GeocoderTest < Test::Unit::TestCase
351
411
  assert_match "appid=MY_KEY", g.send(:query_url, "Madison Square Garden, New York, NY 10001, United States")
352
412
  end
353
413
 
354
- def test_detection_of_coordinates_in_search_string
355
- Geocoder::Configuration.lookup = :geocoder_ca
356
- result = Geocoder.search("51.178844, -1.826189").first
357
- assert_not_nil result.city
358
- # city only present if reverse geocoding search performed
359
- end
360
-
361
414
 
362
415
  private # ------------------------------------------------------------------
363
416
 
metadata CHANGED
@@ -2,21 +2,21 @@
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.11
5
+ version: 0.9.12
6
6
  platform: ruby
7
7
  authors:
8
- - Alex Reisner
8
+ - Alex Reisner
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-25 00:00:00 -04:00
13
+ date: 2011-04-06 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance calculations. Designed for Rails but works with other Rack frameworks too.
17
+ description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance queries for ActiveRecord and Mongoid. Designed for Rails but works with other Rack frameworks too.
18
18
  email:
19
- - alex@alexreisner.com
19
+ - alex@alexreisner.com
20
20
  executables: []
21
21
 
22
22
  extensions: []
@@ -24,45 +24,49 @@ extensions: []
24
24
  extra_rdoc_files: []
25
25
 
26
26
  files:
27
- - .gitignore
28
- - CHANGELOG.rdoc
29
- - LICENSE
30
- - README.rdoc
31
- - Rakefile
32
- - VERSION
33
- - lib/geocoder.rb
34
- - lib/geocoder/cache.rb
35
- - lib/geocoder/calculations.rb
36
- - lib/geocoder/configuration.rb
37
- - lib/geocoder/lookups/base.rb
38
- - lib/geocoder/lookups/freegeoip.rb
39
- - lib/geocoder/lookups/geocoder_ca.rb
40
- - lib/geocoder/lookups/google.rb
41
- - lib/geocoder/lookups/yahoo.rb
42
- - lib/geocoder/orms/active_record.rb
43
- - lib/geocoder/orms/active_record_legacy.rb
44
- - lib/geocoder/orms/base.rb
45
- - lib/geocoder/railtie.rb
46
- - lib/geocoder/request.rb
47
- - lib/geocoder/results/base.rb
48
- - lib/geocoder/results/freegeoip.rb
49
- - lib/geocoder/results/geocoder_ca.rb
50
- - lib/geocoder/results/google.rb
51
- - lib/geocoder/results/yahoo.rb
52
- - lib/tasks/geocoder.rake
53
- - test/fixtures/freegeoip_74_200_247_59.json
54
- - test/fixtures/geocoder_ca_madison_square_garden.json
55
- - test/fixtures/geocoder_ca_no_results.json
56
- - test/fixtures/geocoder_ca_reverse.json
57
- - test/fixtures/google_garbage.json
58
- - test/fixtures/google_madison_square_garden.json
59
- - test/fixtures/google_no_locality.json
60
- - test/fixtures/google_no_results.json
61
- - test/fixtures/yahoo_garbage.json
62
- - test/fixtures/yahoo_madison_square_garden.json
63
- - test/fixtures/yahoo_no_results.json
64
- - test/geocoder_test.rb
65
- - test/test_helper.rb
27
+ - .gitignore
28
+ - CHANGELOG.rdoc
29
+ - LICENSE
30
+ - README.rdoc
31
+ - Rakefile
32
+ - VERSION
33
+ - lib/geocoder.rb
34
+ - lib/geocoder/cache.rb
35
+ - lib/geocoder/calculations.rb
36
+ - lib/geocoder/configuration.rb
37
+ - lib/geocoder/lookups/base.rb
38
+ - lib/geocoder/lookups/freegeoip.rb
39
+ - lib/geocoder/lookups/geocoder_ca.rb
40
+ - lib/geocoder/lookups/google.rb
41
+ - lib/geocoder/lookups/yahoo.rb
42
+ - lib/geocoder/models/active_record.rb
43
+ - lib/geocoder/models/base.rb
44
+ - lib/geocoder/models/mongoid.rb
45
+ - lib/geocoder/railtie.rb
46
+ - lib/geocoder/request.rb
47
+ - lib/geocoder/results/base.rb
48
+ - lib/geocoder/results/freegeoip.rb
49
+ - lib/geocoder/results/geocoder_ca.rb
50
+ - lib/geocoder/results/google.rb
51
+ - lib/geocoder/results/yahoo.rb
52
+ - lib/geocoder/stores/active_record.rb
53
+ - lib/geocoder/stores/active_record_legacy.rb
54
+ - lib/geocoder/stores/base.rb
55
+ - lib/geocoder/stores/mongoid.rb
56
+ - lib/tasks/geocoder.rake
57
+ - test/fixtures/freegeoip_74_200_247_59.json
58
+ - test/fixtures/geocoder_ca_madison_square_garden.json
59
+ - test/fixtures/geocoder_ca_no_results.json
60
+ - test/fixtures/geocoder_ca_reverse.json
61
+ - test/fixtures/google_garbage.json
62
+ - test/fixtures/google_madison_square_garden.json
63
+ - test/fixtures/google_no_locality.json
64
+ - test/fixtures/google_no_results.json
65
+ - test/fixtures/yahoo_garbage.json
66
+ - test/fixtures/yahoo_madison_square_garden.json
67
+ - test/fixtures/yahoo_no_results.json
68
+ - test/geocoder_test.rb
69
+ - test/test_helper.rb
66
70
  has_rdoc: true
67
71
  homepage: http://www.rubygeocoder.com
68
72
  licenses: []
@@ -71,23 +75,23 @@ post_install_message:
71
75
  rdoc_options: []
72
76
 
73
77
  require_paths:
74
- - lib
78
+ - lib
75
79
  required_ruby_version: !ruby/object:Gem::Requirement
76
80
  none: false
77
81
  requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
81
85
  required_rubygems_version: !ruby/object:Gem::Requirement
82
86
  none: false
83
87
  requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
87
91
  requirements: []
88
92
 
89
93
  rubyforge_project:
90
- rubygems_version: 1.5.1
94
+ rubygems_version: 1.6.2
91
95
  signing_key:
92
96
  specification_version: 3
93
97
  summary: Complete geocoding solution for Ruby.