geokit 1.2.5 → 1.2.6

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.
@@ -1,3 +1,6 @@
1
+ === 1.2.6 / 2009-03-19
2
+ * misc minor fixes
3
+
1
4
  === 1.2.5 / 2009-02-25
2
5
 
3
6
  * fixed GeoLoc.to_yaml
@@ -27,3 +30,21 @@
27
30
  * fixed a problem with columns with "distance" in their name
28
31
  * added Geonames geocoder
29
32
  * the gem and plugin are now hosted at Github.
33
+
34
+ === 1.1.1 / 2008-01-20
35
+ * fixes for distance calculation (in-memory and database) when distances are either very small or 0.
36
+ * NOTE: older versions of MySQL/Postgres may not work. See readme for more info.
37
+
38
+ === 1.1.0 / 2007-12-07
39
+ * Geokit is now Rails 2.0 / Edge friendly.
40
+
41
+ === 1.0.0 / 2007-07-22
42
+ * see http://earthcode.com/blog/2007/07/new_geokit_release.html
43
+ * auto geocoding: an option to automatically geocode a model's address field on create
44
+ * in-memory sort-by-distance for arrays of location objects
45
+ * bounding box queries: `Location.find :all, :bounds=>[sw,ne]`
46
+ * improved performance by automatically adding a bounding box condition to radial queries
47
+ * new Bounds class for in-memory bounds-related operations
48
+ * ability to calculate heading and midpoint between two points
49
+ * ability to calculate endpoint given a point, heading, and distance
50
+
@@ -16,8 +16,7 @@ Combine this gem with the [geokit-rails plugin](http://github.com/andre/geokit-r
16
16
 
17
17
  ## INSTALL
18
18
 
19
- gem sources -a http://gems.github.com
20
- sudo gem install andre-geokit
19
+ sudo gem install geokit
21
20
 
22
21
  ## QUICK START
23
22
 
data/Rakefile CHANGED
@@ -4,10 +4,11 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/geokit.rb'
6
6
 
7
- Hoe.new('geokit', Geokit::VERSION) do |p|
7
+ project=Hoe.new('geokit', Geokit::VERSION) do |p|
8
8
  #p.rubyforge_name = 'geokit' # if different than lowercase project name
9
9
  p.developer('Andre Lewis', 'andre@earthcode.com')
10
10
  p.summary="Geokit provides geocoding and distance calculation in an easy-to-use API"
11
11
  end
12
12
 
13
+
13
14
  # vim: syntax=Ruby
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{geokit}
5
- s.version = "1.2.5"
5
+ s.version = "1.2.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andre Lewis and Bill Eisenhauer"]
@@ -1,5 +1,5 @@
1
1
  module Geokit
2
- VERSION = '1.2.5'
2
+ VERSION = '1.2.6'
3
3
  # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
4
4
  @@default_units = :miles
5
5
  @@default_formula = :sphere
@@ -26,5 +26,5 @@ $: << path unless $:.include?(path)
26
26
  require 'geokit/geocoders'
27
27
  require 'geokit/mappable'
28
28
 
29
- # make old-style module name "GeoKit" equivilent to new-style "Geokit"
29
+ # make old-style module name "GeoKit" equivalent to new-style "Geokit"
30
30
  GeoKit=Geokit
@@ -105,7 +105,7 @@ module Geokit
105
105
  # empty one with a failed success code.
106
106
  def self.geocode(address)
107
107
  res = do_geocode(address)
108
- return res.success ? res : GeoLoc.new
108
+ return res.success? ? res : GeoLoc.new
109
109
  end
110
110
 
111
111
  # Main method which calls the do_reverse_geocode template method which subclasses
@@ -113,7 +113,7 @@ module Geokit
113
113
  # empty one with a failed success code.
114
114
  def self.reverse_geocode(latlng)
115
115
  res = do_reverse_geocode(latlng)
116
- return res.success ? res : GeoLoc.new
116
+ return res.success? ? res : GeoLoc.new
117
117
  end
118
118
 
119
119
  # Call the geocoder service using the timeout if configured.
@@ -400,7 +400,7 @@ module Geokit
400
400
  # Google can return multiple results as //Placemark elements.
401
401
  # iterate through each and extract each placemark as a geoloc
402
402
  doc.each_element('//Placemark') do |e|
403
- extracted_geoloc = extract_placemark(e) # g is now an instance of Geoloc
403
+ extracted_geoloc = extract_placemark(e) # g is now an instance of GeoLoc
404
404
  if geoloc.nil?
405
405
  # first time through, geoloc is still nil, so we make it the geoloc we just extracted
406
406
  geoloc = extracted_geoloc
@@ -492,7 +492,7 @@ module Geokit
492
492
  # longitude, city, and country code. Sets the success attribute to false if the ip
493
493
  # parameter does not match an ip address.
494
494
  def self.do_geocode(ip)
495
- return Geoloc.new if '0.0.0.0' == ip
495
+ return GeoLoc.new if '0.0.0.0' == ip
496
496
  return GeoLoc.new unless /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(ip)
497
497
  url = "http://api.hostip.info/get_html.php?ip=#{ip}&position=true"
498
498
  response = self.call_geocoder_service(url)
@@ -550,7 +550,7 @@ module Geokit
550
550
  begin
551
551
  klass = Geokit::Geocoders.const_get "#{provider.to_s.capitalize}Geocoder"
552
552
  res = klass.send :geocode, address
553
- return res if res.success
553
+ return res if res.success?
554
554
  rescue
555
555
  logger.error("Something has gone very wrong during geocoding, OR you have configured an invalid class name in Geokit::Geocoders::provider_order. Address: #{address}. Provider: #{provider}")
556
556
  end
@@ -112,7 +112,7 @@ module Geokit
112
112
  # Geocodes a location using the multi geocoder.
113
113
  def geocode(location)
114
114
  res = Geocoders::MultiGeocoder.geocode(location)
115
- return res if res.success
115
+ return res if res.success?
116
116
  raise Geokit::Geocoders::GeocodeError
117
117
  end
118
118
 
@@ -270,7 +270,7 @@ module Geokit
270
270
  return Geokit::LatLng.new(match[1],match[2])
271
271
  else
272
272
  res = Geokit::Geocoders::MultiGeocoder.geocode(thing)
273
- return res if res.success
273
+ return res if res.success?
274
274
  raise Geokit::Geocoders::GeocodeError
275
275
  end
276
276
  elsif thing.is_a?(Array) && thing.size==2
@@ -337,6 +337,10 @@ module Geokit
337
337
  def is_us?
338
338
  country_code == 'US'
339
339
  end
340
+
341
+ def success?
342
+ success == true
343
+ end
340
344
 
341
345
  # full_address is provided by google but not by yahoo. It is intended that the google
342
346
  # geocoding method will provide the full address, whereas for yahoo it will be derived
@@ -17,6 +17,12 @@ end
17
17
  # Base class for testing geocoders.
18
18
  class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
19
19
 
20
+ class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
21
+ def self.do_get(url)
22
+ sleep(2)
23
+ end
24
+ end
25
+
20
26
  # Defines common test fixtures.
21
27
  def setup
22
28
  @address = 'San Francisco, CA'
@@ -28,14 +34,9 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
28
34
  end
29
35
 
30
36
  def test_timeout_call_web_service
31
- Geokit::Geocoders::Geocoder.class_eval do
32
- def self.do_get(url)
33
- sleep(2)
34
- end
35
- end
36
37
  url = "http://www.anything.com"
37
38
  Geokit::Geocoders::timeout = 1
38
- assert_nil Geokit::Geocoders::Geocoder.call_geocoder_service(url)
39
+ assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
39
40
  end
40
41
 
41
42
  def test_successful_call_web_service
@@ -13,6 +13,14 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
13
13
  assert @loc.is_us?
14
14
  end
15
15
 
16
+ def test_success
17
+ assert !@loc.success?
18
+ @loc.success = false
19
+ assert !@loc.success?
20
+ @loc.success = true
21
+ assert @loc.success?
22
+ end
23
+
16
24
  def test_street_number
17
25
  @loc.street_address = '123 Spear St.'
18
26
  assert_equal '123', @loc.street_number
@@ -39,13 +39,13 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
39
39
  assert_equal "Minas Gerais", location.state
40
40
  assert_equal "BR", location.country_code
41
41
  assert_equal "geoPlugin", location.provider
42
- assert location.success
42
+ assert location.success?
43
43
  end
44
44
 
45
45
  def test_invalid_ip
46
46
  location = GeoKit::Geocoders::GeoPluginGeocoder.geocode("pixrum")
47
47
  assert_not_nil location
48
- assert !location.success
48
+ assert !location.success?
49
49
  end
50
50
 
51
51
  def test_service_unavailable
@@ -54,6 +54,6 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
54
54
  GeoKit::Geocoders::GeoPluginGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
55
55
  location = GeoKit::Geocoders::GeoPluginGeocoder.geocode("10.10.10.10")
56
56
  assert_not_nil location
57
- assert !location.success
57
+ assert !location.success?
58
58
  end
59
59
  end
@@ -42,7 +42,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
42
42
  assert_equal "IL", location.state
43
43
  assert_equal "US", location.country_code
44
44
  assert_equal "hostip", location.provider
45
- assert location.success
45
+ assert location.success?
46
46
  end
47
47
 
48
48
  def test_unicoded_lookup
@@ -58,7 +58,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
58
58
  assert_nil location.state
59
59
  assert_equal "SE", location.country_code
60
60
  assert_equal "hostip", location.provider
61
- assert location.success
61
+ assert location.success?
62
62
  end
63
63
 
64
64
  def test_failed_lookup
@@ -68,13 +68,13 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
68
68
  GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
69
69
  location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10")
70
70
  assert_not_nil location
71
- assert !location.success
71
+ assert !location.success?
72
72
  end
73
73
 
74
74
  def test_invalid_ip
75
75
  location = GeoKit::Geocoders::IpGeocoder.geocode("blah")
76
76
  assert_not_nil location
77
- assert !location.success
77
+ assert !location.success?
78
78
  end
79
79
 
80
80
  def test_service_unavailable
@@ -83,6 +83,6 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
83
83
  GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
84
84
  location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10")
85
85
  assert_not_nil location
86
- assert !location.success
86
+ assert !location.success?
87
87
  end
88
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Lewis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-03 00:00:00 -08:00
12
+ date: 2009-03-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency