ggeocode 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ggeocode.gemspec +1 -1
- data/lib/ggeocode.rb +52 -10
- metadata +4 -4
data/ggeocode.gemspec
CHANGED
data/lib/ggeocode.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module GGeocode
|
2
|
+
### ref: http://code.google.com/apis/maps/documentation/geocoding/
|
2
3
|
|
3
|
-
GGeocode::Version = '0.0.
|
4
|
+
GGeocode::Version = '0.0.3'
|
4
5
|
|
5
6
|
def GGeocode.version
|
6
7
|
GGeocode::Version
|
@@ -21,24 +22,43 @@ module GGeocode
|
|
21
22
|
require 'yajl/json_gem'
|
22
23
|
require 'map'
|
23
24
|
|
25
|
+
AddressPattern = /\w/iox
|
24
26
|
|
25
|
-
def geocode(
|
26
|
-
|
27
|
+
def geocode(*args, &block)
|
28
|
+
options = Map.options_for!(args)
|
29
|
+
if options[:reverse]
|
30
|
+
args.push(options)
|
31
|
+
return reverse_geocode(*args, &block)
|
32
|
+
end
|
33
|
+
string = args.join(' ')
|
34
|
+
address = address_for(string)
|
35
|
+
response = get(url_for(:address => address))
|
27
36
|
result_for(response)
|
28
37
|
end
|
29
38
|
|
30
|
-
def reverse_geocode(
|
31
|
-
|
39
|
+
def reverse_geocode(*args, &block)
|
40
|
+
options = Map.options_for!(args)
|
41
|
+
string = args.join(' ')
|
42
|
+
latlng = latlng_for(string)
|
43
|
+
response = get(url_for(:latlng => latlng))
|
32
44
|
result_for(response)
|
33
45
|
end
|
34
46
|
alias_method('rgeocode', 'reverse_geocode')
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
def GGeocode.call(*args, &block)
|
49
|
+
options = Map.options_for!(args)
|
50
|
+
string = args.join(' ')
|
51
|
+
reverse = string !~ AddressPattern || options[:reverse]
|
52
|
+
reverse ? GGeocode.reverse_geocode(string) : GGeocode.geocode(string)
|
53
|
+
end
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
|
55
|
+
def latlng_for(string)
|
56
|
+
lat, lng = string.scan(/[^\s,]+/)
|
57
|
+
latlng = [lat, lng].join(',')
|
58
|
+
end
|
59
|
+
|
60
|
+
def address_for(string)
|
61
|
+
string.to_s.strip
|
42
62
|
end
|
43
63
|
|
44
64
|
def result_for(response)
|
@@ -53,6 +73,14 @@ module GGeocode
|
|
53
73
|
map
|
54
74
|
end
|
55
75
|
|
76
|
+
module Response
|
77
|
+
attr_accessor :response
|
78
|
+
def body
|
79
|
+
response.body
|
80
|
+
end
|
81
|
+
alias_method('json', 'body')
|
82
|
+
end
|
83
|
+
|
56
84
|
Url = URI.parse("http://maps.google.com/maps/api/geocode/json?")
|
57
85
|
|
58
86
|
def url_for(options = {})
|
@@ -92,8 +120,22 @@ module GGeocode
|
|
92
120
|
extend(GGeocode)
|
93
121
|
end
|
94
122
|
|
123
|
+
module Kernel
|
124
|
+
private
|
125
|
+
def GGeocode(*args, &block)
|
126
|
+
GGeocode.call(*args, &block)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
95
130
|
Ggeocode = GGeocode
|
96
131
|
|
132
|
+
BEGIN {
|
133
|
+
if defined?(GGeocode)
|
134
|
+
Object.send(:remove_const, :GGeocode)
|
135
|
+
Object.send(:remove_const, :Ggeocode)
|
136
|
+
end
|
137
|
+
}
|
138
|
+
|
97
139
|
|
98
140
|
if $0 == __FILE__
|
99
141
|
require 'pp'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ggeocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|