andre-geokit 1.2.1 → 1.2.2
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/lib/geokit/geocoders.rb +10 -9
- data/lib/geokit/mappable.rb +8 -8
- data/test/test_base_geocoder.rb +2 -2
- metadata +4 -12
data/lib/geokit/geocoders.rb
CHANGED
@@ -10,13 +10,13 @@ module Geokit
|
|
10
10
|
extend self
|
11
11
|
|
12
12
|
def titleize(word)
|
13
|
-
humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
|
13
|
+
humanize(underscore(word)).gsub(/\b([a-z])/u) { $1.capitalize }
|
14
14
|
end
|
15
15
|
|
16
16
|
def underscore(camel_cased_word)
|
17
17
|
camel_cased_word.to_s.gsub(/::/, '/').
|
18
|
-
gsub(/([A-Z]+)([A-Z][a-z])
|
19
|
-
gsub(/([a-z\d])([A-Z])
|
18
|
+
gsub(/([A-Z]+)([A-Z][a-z])/u,'\1_\2').
|
19
|
+
gsub(/([a-z\d])([A-Z])/u,'\1_\2').
|
20
20
|
tr("-", "_").
|
21
21
|
downcase
|
22
22
|
end
|
@@ -26,14 +26,14 @@ module Geokit
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def snake_case(s)
|
29
|
-
return s.downcase if s =~ /^[A-Z]+$/
|
30
|
-
s.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]
|
29
|
+
return s.downcase if s =~ /^[A-Z]+$/u
|
30
|
+
s.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/u, '_\&') =~ /_*(.*)/
|
31
31
|
return $+.downcase
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def url_escape(s)
|
36
|
-
s.gsub(/([^ a-zA-Z0-9_.-]+)/
|
36
|
+
s.gsub(/([^ a-zA-Z0-9_.-]+)/nu) do
|
37
37
|
'%' + $1.unpack('H2' * $1.size).join('%').upcase
|
38
38
|
end.tr(' ', '+')
|
39
39
|
end
|
@@ -211,11 +211,12 @@ module Geokit
|
|
211
211
|
|
212
212
|
# Template method which does the reverse-geocode lookup.
|
213
213
|
def self.do_reverse_geocode(latlng)
|
214
|
-
|
214
|
+
latlng=LatLng.normalize(latlng)
|
215
|
+
res = self.call_geocoder_service("http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(latlng.ll)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8")
|
215
216
|
# res = Net::HTTP.get_response(URI.parse("http://maps.google.com/maps/geo?ll=#{Geokit::Inflector::url_escape(address_str)}&output=xml&key=#{Geokit::Geocoders::google}&oe=utf-8"))
|
216
217
|
return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
|
217
218
|
xml = res.body
|
218
|
-
logger.debug "Google reverse-geocoding. LL: #{latlng}. Result: #{xml}"
|
219
|
+
logger.debug "Google reverse-geocoding. LL: #{latlng.ll}. Result: #{xml}"
|
219
220
|
return self.xml2GeoLoc(xml)
|
220
221
|
end
|
221
222
|
|
@@ -482,4 +483,4 @@ module Geokit
|
|
482
483
|
end
|
483
484
|
end
|
484
485
|
end
|
485
|
-
end
|
486
|
+
end
|
data/lib/geokit/mappable.rb
CHANGED
@@ -75,8 +75,8 @@ module Geokit
|
|
75
75
|
def endpoint(start,heading, distance, options={})
|
76
76
|
units = options[:units] || Geokit::default_units
|
77
77
|
radius = case units
|
78
|
-
when :kms
|
79
|
-
when :nms
|
78
|
+
when :kms; EARTH_RADIUS_IN_KMS
|
79
|
+
when :nms; EARTH_RADIUS_IN_NMS
|
80
80
|
else EARTH_RADIUS_IN_MILES
|
81
81
|
end
|
82
82
|
start=Geokit::LatLng.normalize(start)
|
@@ -132,8 +132,8 @@ module Geokit
|
|
132
132
|
# Returns the multiplier used to obtain the correct distance units.
|
133
133
|
def units_sphere_multiplier(units)
|
134
134
|
case units
|
135
|
-
when :kms
|
136
|
-
when :nms
|
135
|
+
when :kms; EARTH_RADIUS_IN_KMS
|
136
|
+
when :nms; EARTH_RADIUS_IN_NMS
|
137
137
|
else EARTH_RADIUS_IN_MILES
|
138
138
|
end
|
139
139
|
end
|
@@ -141,8 +141,8 @@ module Geokit
|
|
141
141
|
# Returns the number of units per latitude degree.
|
142
142
|
def units_per_latitude_degree(units)
|
143
143
|
case units
|
144
|
-
when :kms
|
145
|
-
when :nms
|
144
|
+
when :kms; KMS_PER_LATITUDE_DEGREE
|
145
|
+
when :nms; NMS_PER_LATITUDE_DEGREE
|
146
146
|
else MILES_PER_LATITUDE_DEGREE
|
147
147
|
end
|
148
148
|
end
|
@@ -151,8 +151,8 @@ module Geokit
|
|
151
151
|
def units_per_longitude_degree(lat, units)
|
152
152
|
miles_per_longitude_degree = (LATITUDE_DEGREES * Math.cos(lat * PI_DIV_RAD)).abs
|
153
153
|
case units
|
154
|
-
when :kms
|
155
|
-
when :nms
|
154
|
+
when :kms; miles_per_longitude_degree * KMS_PER_MILE
|
155
|
+
when :nms; miles_per_longitude_degree * NMS_PER_MILE
|
156
156
|
else miles_per_longitude_degree
|
157
157
|
end
|
158
158
|
end
|
data/test/test_base_geocoder.rb
CHANGED
@@ -45,7 +45,7 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_find_geocoder_methods
|
48
|
-
public_methods = Geokit::Geocoders::Geocoder.public_methods
|
48
|
+
public_methods = Geokit::Geocoders::Geocoder.public_methods.map { |m| m.to_s }
|
49
49
|
assert public_methods.include?("yahoo_geocoder")
|
50
50
|
assert public_methods.include?("google_geocoder")
|
51
51
|
assert public_methods.include?("ca_geocoder")
|
@@ -53,4 +53,4 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
|
|
53
53
|
assert public_methods.include?("multi_geocoder")
|
54
54
|
assert public_methods.include?("ip_geocoder")
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
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.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Lewis and Bill Eisenhauer
|
@@ -9,18 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: hoe
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 1.8.2
|
23
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
24
16
|
description: Geokit Gem
|
25
17
|
email:
|
26
18
|
- andre@earthcode.com / bill_eisenhauer@yahoo.com
|