andre-geokit 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
@@ -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('Geokit', Geokit::VERSION) do |p|
8
- # p.rubyforge_name = 'Geokitx' # if different than lowercase project name
9
- p.developer('Andre Lewis and Bill Eisenhauer', 'andre@earthcode.com / bill_eisenhauer@yahoo.com')
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
@@ -1,5 +1,5 @@
1
1
  module Geokit
2
- VERSION = '1.2.0'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: andre-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 and Bill Eisenhauer