andre-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.
- data/Manifest.txt +3 -0
- data/README.markdown +1 -2
- data/Rakefile +5 -11
- data/lib/geokit.rb +2 -2
- data/lib/geokit/geocoders.rb +5 -5
- data/lib/geokit/mappable.rb +6 -2
- data/test/test_base_geocoder.rb +7 -6
- data/test/test_geoloc.rb +8 -0
- metadata +1 -1
data/Manifest.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
.project
|
2
|
+
History.txt
|
2
3
|
Manifest.txt
|
3
4
|
README.markdown
|
4
5
|
Rakefile
|
@@ -10,8 +11,10 @@ test/test_base_geocoder.rb
|
|
10
11
|
test/test_bounds.rb
|
11
12
|
test/test_ca_geocoder.rb
|
12
13
|
test/test_geoloc.rb
|
14
|
+
test/test_geoplugin_geocoder.rb
|
13
15
|
test/test_google_geocoder.rb
|
14
16
|
test/test_google_reverse_geocoder.rb
|
17
|
+
test/test_inflector.rb
|
15
18
|
test/test_ipgeocoder.rb
|
16
19
|
test/test_latlng.rb
|
17
20
|
test/test_multi_geocoder.rb
|
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -2,19 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'hoe'
|
5
|
-
require './lib/geokit'
|
5
|
+
require './lib/geokit.rb'
|
6
6
|
|
7
|
-
Hoe.new('
|
8
|
-
#
|
9
|
-
p.developer('Andre Lewis
|
7
|
+
project=Hoe.new('geokit', Geokit::VERSION) do |p|
|
8
|
+
#p.rubyforge_name = 'geokit' # if different than lowercase project name
|
9
|
+
p.developer('Andre Lewis', 'andre@earthcode.com')
|
10
|
+
p.summary="Geokit provides geocoding and distance calculation in an easy-to-use API"
|
10
11
|
end
|
11
12
|
|
12
|
-
task :generate_gemspec do
|
13
|
-
system "rake debug_gem | grep -v \"(in \" > `basename \\`pwd\\``.gemspec"
|
14
|
-
end
|
15
|
-
|
16
|
-
task :update_manifest do
|
17
|
-
system "touch Manifest.txt; rake check_manifest | grep -v \"(in \" | patch"
|
18
|
-
end
|
19
13
|
|
20
14
|
# vim: syntax=Ruby
|
data/lib/geokit.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Geokit
|
2
|
-
VERSION = '1.2.
|
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"
|
29
|
+
# make old-style module name "GeoKit" equivalent to new-style "Geokit"
|
30
30
|
GeoKit=Geokit
|
data/lib/geokit/geocoders.rb
CHANGED
@@ -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
|
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
|
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
|
data/lib/geokit/mappable.rb
CHANGED
@@ -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
|
data/test/test_base_geocoder.rb
CHANGED
@@ -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::
|
39
|
+
assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
|
39
40
|
end
|
40
41
|
|
41
42
|
def test_successful_call_web_service
|
data/test/test_geoloc.rb
CHANGED
@@ -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
|