normalic 0.1.0 → 0.1.1
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 +4 -1
- data/README.rdoc +20 -4
- data/Rakefile +1 -1
- data/lib/constants.rb +41950 -41953
- data/lib/normalic.rb +23 -117
- data/lib/normalic/address.rb +236 -0
- data/lib/normalic/phone_number.rb +49 -0
- data/lib/normalic/uri.rb +140 -0
- data/normalic.gemspec +14 -14
- data/spec/normalic_spec.rb +271 -29
- metadata +11 -5
data/normalic.gemspec
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.1.
|
4
|
+
s.name = "normalic"
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
14
|
-
s.homepage =
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
8
|
+
s.authors = ["Eric Tang"]
|
9
|
+
s.date = "2011-10-26"
|
10
|
+
s.description = "Normalize U.S addresses"
|
11
|
+
s.email = "eric.x.tang@gmail.com"
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/constants.rb", "lib/normalic.rb", "lib/normalic/address.rb", "lib/normalic/phone_number.rb", "lib/normalic/uri.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/constants.rb", "lib/normalic.rb", "lib/normalic/address.rb", "lib/normalic/phone_number.rb", "lib/normalic/uri.rb", "spec/normalic_spec.rb", "normalic.gemspec"]
|
14
|
+
s.homepage = "http://github.com/ericxtang/normalic"
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Normalic", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "normalic"
|
18
|
+
s.rubygems_version = "1.8.10"
|
19
|
+
s.summary = "Normalize U.S addresses"
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
s.specification_version = 3
|
data/spec/normalic_spec.rb
CHANGED
@@ -1,78 +1,320 @@
|
|
1
1
|
require 'lib/normalic'
|
2
2
|
|
3
|
-
|
3
|
+
|
4
|
+
describe "Normalic::URI" do
|
5
|
+
|
6
|
+
it "should parse a well-formatted URI" do
|
7
|
+
uri = Normalic::URI.parse("http://mike@mkscrg.github.com:80/about.html?lang=ruby&dvcs=git#blog")
|
8
|
+
uri[:scheme].should == "http"
|
9
|
+
uri[:user].should == "mike"
|
10
|
+
uri[:subdomain].should == "mkscrg"
|
11
|
+
uri[:domain].should == "github"
|
12
|
+
uri[:tld].should == "com"
|
13
|
+
uri[:port].should == "80"
|
14
|
+
uri[:path].should == "/about.html"
|
15
|
+
uri[:query_hash].should == {"lang" => "ruby", "dvcs" => "git"}
|
16
|
+
uri[:fragment].should == "blog"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should print a parsed URI correctly" do
|
20
|
+
uri = Normalic::URI.parse("http://mike@mkscrg.github.com:80/about.html?lang=ruby&dvcs=git#blog")
|
21
|
+
["http://mike@mkscrg.github.com:80/about.html?lang=ruby&dvcs=git#blog",
|
22
|
+
"http://mike@mkscrg.github.com:80/about.html?dvcs=git&lang=ruby#blog"].include?(uri.to_s.should)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should parse a bare domain and tld with default scheme and subdomain" do
|
26
|
+
uri = Normalic::URI.parse("github.com")
|
27
|
+
uri[:scheme].should == "http"
|
28
|
+
uri[:user].should == nil
|
29
|
+
uri[:subdomain].should == "www"
|
30
|
+
uri[:domain].should == "github"
|
31
|
+
uri[:tld].should == "com"
|
32
|
+
uri[:port].should == nil
|
33
|
+
uri[:path].should == "/"
|
34
|
+
uri[:query_hash].should == nil
|
35
|
+
uri[:fragment].should == nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should normalize consecutive slashes and strip trailing slashes in the path" do
|
39
|
+
uri = Normalic::URI.parse("https://github.com/mkscrg//normalic/")
|
40
|
+
uri[:scheme].should == "https"
|
41
|
+
uri[:user].should == nil
|
42
|
+
uri[:subdomain].should == "www"
|
43
|
+
uri[:domain].should == "github"
|
44
|
+
uri[:tld].should == "com"
|
45
|
+
uri[:port].should == nil
|
46
|
+
uri[:path].should == "/mkscrg/normalic"
|
47
|
+
uri[:query_hash].should == nil
|
48
|
+
uri[:fragment].should == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should normalize relative path segments: '.' and '..'" do
|
52
|
+
uri = Normalic::URI.parse("github.com/ericxtang/expresso/../normalic")
|
53
|
+
uri[:scheme].should == "http"
|
54
|
+
uri[:user].should == nil
|
55
|
+
uri[:subdomain].should == "www"
|
56
|
+
uri[:domain].should == "github"
|
57
|
+
uri[:tld].should == "com"
|
58
|
+
uri[:port].should == nil
|
59
|
+
uri[:path].should == "/ericxtang/normalic"
|
60
|
+
uri[:query_hash].should == nil
|
61
|
+
uri[:fragment].should == nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should match_essential? a nil subdomain against a 'www' subdomain" do
|
65
|
+
uri1 = Normalic::URI.parse("http://www.github.com")
|
66
|
+
uri2 = Normalic::URI.parse("http://github.com")
|
67
|
+
uri1.match_essential?(uri2).should == true
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should match_essential? using the subdomain, domain, and tld" do
|
71
|
+
uri1 = Normalic::URI.parse("http://www.hyperpublic.com")
|
72
|
+
uri2 = Normalic::URI.parse("http://oxcart.hyperpublic.com")
|
73
|
+
uri1.match_essential?(uri2).should == false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should match_essential? using ONLY the subdomain, domain, and tld" do
|
77
|
+
uri1 = Normalic::URI.parse("http://www.hyperpublic.com/placesplus")
|
78
|
+
uri2 = Normalic::URI.parse("http://www.hyperpublic.com/deals")
|
79
|
+
uri1.match_essential?(uri2).should == true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should be nondestructive" do
|
83
|
+
raw = "github.com"
|
84
|
+
raw_orig = raw.clone
|
85
|
+
uri = Normalic::URI.parse(raw)
|
86
|
+
raw_orig.should == raw
|
87
|
+
uri[:scheme].should == "http"
|
88
|
+
uri[:user].should == nil
|
89
|
+
uri[:subdomain].should == "www"
|
90
|
+
uri[:domain].should == "github"
|
91
|
+
uri[:tld].should == "com"
|
92
|
+
uri[:port].should == nil
|
93
|
+
uri[:path].should == "/"
|
94
|
+
uri[:query_hash].should == nil
|
95
|
+
uri[:fragment].should == nil
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
describe "Normalic::PhoneNumber" do
|
102
|
+
|
103
|
+
it "should parse a bare phone number" do
|
104
|
+
ph = Normalic::PhoneNumber.parse("2345678901")
|
105
|
+
ph[:npa].should == "234"
|
106
|
+
ph[:nxx].should == "567"
|
107
|
+
ph[:slid].should == "8901"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should parse a phone number with an extension given" do
|
111
|
+
ph = Normalic::PhoneNumber.parse("2345678901 ext. 555")
|
112
|
+
ph[:npa].should == "234"
|
113
|
+
ph[:nxx].should == "567"
|
114
|
+
ph[:slid].should == "8901"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should parse a phone number with 1 in front" do
|
118
|
+
ph = Normalic::PhoneNumber.parse("12345678901")
|
119
|
+
ph[:npa].should == "234"
|
120
|
+
ph[:nxx].should == "567"
|
121
|
+
ph[:slid].should == "8901"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should parse a phone number with non-digit formatting" do
|
125
|
+
ph = Normalic::PhoneNumber.parse("+1 (234) 567 - 8901")
|
126
|
+
ph[:npa].should == "234"
|
127
|
+
ph[:nxx].should == "567"
|
128
|
+
ph[:slid].should == "8901"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should be nondestructive" do
|
132
|
+
raw = "2345678901"
|
133
|
+
raw_orig = raw.clone
|
134
|
+
ph = Normalic::PhoneNumber.parse(raw)
|
135
|
+
raw_orig.should == raw
|
136
|
+
ph[:npa].should == "234"
|
137
|
+
ph[:nxx].should == "567"
|
138
|
+
ph[:slid].should == "8901"
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
describe "Normalic::Address" do
|
4
145
|
|
5
146
|
it "should parse an address with unit(floor) information" do
|
6
147
|
addr = Normalic::Address.parse("201 Varick St. floor 12th, New York, NY 10014")
|
7
148
|
addr[:number].should == "201"
|
8
|
-
addr[:
|
9
|
-
addr[:
|
10
|
-
addr[:
|
11
|
-
addr[:
|
149
|
+
addr[:direction].should == nil
|
150
|
+
addr[:street].should == "Varick"
|
151
|
+
addr[:type].should == "St."
|
152
|
+
addr[:city].should == "New York"
|
153
|
+
addr[:state].should == "NY"
|
12
154
|
addr[:zipcode].should == "10014"
|
155
|
+
addr[:intersection].should == false
|
13
156
|
end
|
14
157
|
|
15
158
|
it "should parse an address with direction information" do
|
16
159
|
addr = Normalic::Address.parse("167 West 4th Street, New York, NY 10014")
|
17
160
|
addr[:number].should == "167"
|
161
|
+
addr[:direction].should == "W"
|
162
|
+
addr[:street].should == "4th"
|
163
|
+
addr[:type].should == "St."
|
164
|
+
addr[:city].should == "New York"
|
165
|
+
addr[:state].should == "NY"
|
166
|
+
addr[:zipcode].should == "10014"
|
167
|
+
addr[:intersection].should == false
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should parse an address with direction after the street type" do
|
171
|
+
addr = Normalic::Address.parse("167 4th Street Northeast, New York, NY 10014")
|
172
|
+
addr[:number].should == "167"
|
173
|
+
addr[:direction].should == "NE"
|
18
174
|
addr[:street].should == "4th"
|
19
|
-
addr[:
|
20
|
-
addr[:
|
21
|
-
addr[:
|
22
|
-
addr[:
|
175
|
+
addr[:type].should == "St."
|
176
|
+
addr[:city].should == "New York"
|
177
|
+
addr[:state].should == "NY"
|
178
|
+
addr[:zipcode].should == "10014"
|
179
|
+
addr[:intersection].should == false
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should parse an intersection" do
|
183
|
+
addr = Normalic::Address.parse("9th Ave. and W 13th St., New York, NY 10014")
|
184
|
+
addr[:number].should == nil
|
185
|
+
addr[:direction].should == [nil, "W"]
|
186
|
+
addr[:street].should == ["9th", "13th"]
|
187
|
+
addr[:type].should == ["Ave.", "St."]
|
188
|
+
addr[:city].should == "New York"
|
189
|
+
addr[:state].should == "NY"
|
23
190
|
addr[:zipcode].should == "10014"
|
191
|
+
addr[:intersection].should == true
|
24
192
|
end
|
25
193
|
|
26
|
-
it "should parse an address with incorrect state info" do
|
27
|
-
addr = Normalic::Address.parse("871 Washington Street, New York, NewYork
|
194
|
+
it "should parse an address with incorrect state info and no zipcode" do
|
195
|
+
addr = Normalic::Address.parse("871 Washington Street, New York, NewYork")
|
28
196
|
addr[:number].should == "871"
|
29
|
-
addr[:
|
30
|
-
addr[:
|
31
|
-
addr[:
|
32
|
-
addr[:
|
197
|
+
addr[:direction].should == nil
|
198
|
+
addr[:street].should == "Washington"
|
199
|
+
addr[:type].should == "St."
|
200
|
+
addr[:city].should == "New York"
|
201
|
+
addr[:state].should == "NY"
|
202
|
+
addr[:zipcode].should == nil
|
203
|
+
addr[:intersection].should == false
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should parse an address with no state info" do
|
207
|
+
addr = Normalic::Address.parse("416 W 13th Street, New York, 10014")
|
208
|
+
addr[:number].should == "416"
|
209
|
+
addr[:direction].should == "W"
|
210
|
+
addr[:street].should == "13th"
|
211
|
+
addr[:type].should == "St."
|
212
|
+
addr[:city].should == "New York"
|
213
|
+
addr[:state].should == "NY"
|
33
214
|
addr[:zipcode].should == "10014"
|
215
|
+
addr[:intersection].should == false
|
34
216
|
end
|
35
217
|
|
36
|
-
it "should parse
|
37
|
-
addr = Normalic::Address.parse("
|
218
|
+
it "should parse only a zipcode into a state and city" do
|
219
|
+
addr = Normalic::Address.parse("08848")
|
220
|
+
addr[:number].should == nil
|
221
|
+
addr[:direction].should == nil
|
222
|
+
addr[:street].should == nil
|
223
|
+
addr[:type].should == nil
|
224
|
+
addr[:city].should == "Milford"
|
225
|
+
addr[:state].should == "NJ"
|
226
|
+
addr[:zipcode].should == "08848"
|
227
|
+
addr[:intersection].should == false
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should normalize a zipcode with a +4 code" do
|
231
|
+
addr = Normalic::Address.parse("201 Varick St., New York, NY 10014-1234")
|
38
232
|
addr[:number].should == "201"
|
39
|
-
addr[:
|
40
|
-
addr[:
|
233
|
+
addr[:direction].should == nil
|
234
|
+
addr[:street].should == "Varick"
|
235
|
+
addr[:type].should == "St."
|
236
|
+
addr[:city].should == "New York"
|
237
|
+
addr[:state].should == "NY"
|
238
|
+
addr[:zipcode].should == "10014"
|
239
|
+
addr[:intersection].should == false
|
41
240
|
end
|
42
241
|
|
43
242
|
it "should parse an address with no city info" do
|
44
243
|
addr = Normalic::Address.parse("871 Washington Street")
|
45
244
|
addr[:number].should == "871"
|
46
|
-
addr[:
|
47
|
-
addr[:
|
245
|
+
addr[:direction].should == nil
|
246
|
+
addr[:street].should == "Washington"
|
247
|
+
addr[:type].should == "St."
|
248
|
+
addr[:city].should == nil
|
249
|
+
addr[:state].should == nil
|
250
|
+
addr[:zipcode].should == nil
|
251
|
+
addr[:intersection].should == false
|
48
252
|
end
|
49
253
|
|
254
|
+
it "should parse an address with floor info and without city info" do
|
255
|
+
addr = Normalic::Address.parse("201 Varick St. floor 12th")
|
256
|
+
addr[:number].should == "201"
|
257
|
+
addr[:direction].should == nil
|
258
|
+
addr[:street].should == "Varick"
|
259
|
+
addr[:type].should == "St."
|
260
|
+
addr[:city].should == nil
|
261
|
+
addr[:state].should == nil
|
262
|
+
addr[:zipcode].should == nil
|
263
|
+
addr[:intersection].should == false
|
264
|
+
end
|
50
265
|
|
51
266
|
it "should parse an address with direction info and no city info" do
|
52
267
|
addr = Normalic::Address.parse("871 West Washington Street")
|
53
268
|
addr[:number].should == "871"
|
54
|
-
addr[:
|
55
|
-
addr[:
|
56
|
-
addr[:type].should == "
|
269
|
+
addr[:direction].should == "W"
|
270
|
+
addr[:street].should == "Washington"
|
271
|
+
addr[:type].should == "St."
|
272
|
+
addr[:city].should == nil
|
273
|
+
addr[:state].should == nil
|
274
|
+
addr[:zipcode].should == nil
|
275
|
+
addr[:intersection].should == false
|
57
276
|
end
|
58
277
|
|
59
278
|
it "should use dot notation" do
|
60
|
-
addr = Normalic::Address.parse("871
|
279
|
+
addr = Normalic::Address.parse("871 west washington street, new york, ny 10014")
|
61
280
|
addr.number.should == "871"
|
281
|
+
addr.direction.should == "W"
|
282
|
+
addr.street.should == "Washington"
|
283
|
+
addr.type.should == "St."
|
284
|
+
addr.city.should == "New York"
|
285
|
+
addr.state.should == "NY"
|
286
|
+
addr.zipcode.should == "10014"
|
287
|
+
addr.intersection.should == false
|
62
288
|
end
|
63
289
|
|
64
|
-
it "should return nil if a bad field is passed in" do
|
65
|
-
addr = Normalic::Address.parse("871
|
290
|
+
it "should return nil if a bad field is passed in with index notation" do
|
291
|
+
addr = Normalic::Address.parse("871 west washington street, new york, ny 10014")
|
66
292
|
addr[:bad_name].should == nil
|
67
293
|
end
|
68
294
|
|
69
295
|
it "should return a line1" do
|
70
296
|
addr = Normalic::Address.parse("871 West Washington Street")
|
71
|
-
addr.line1.should == "871 W Washington St"
|
297
|
+
addr.line1.should == "871 W Washington St."
|
72
298
|
end
|
73
299
|
|
74
300
|
it "should have a to_s method" do
|
75
301
|
addr = Normalic::Address.parse("167 West 4th Street, New York, NY 10014")
|
76
|
-
addr.to_s.should == "167 W 4th St
|
302
|
+
addr.to_s.should == "167 W 4th St., New York, NY 10014"
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should be nondestructive" do
|
306
|
+
raw = "167 West 4th Street, New York, NY 10014"
|
307
|
+
raw_orig = raw.clone
|
308
|
+
addr = Normalic::Address.parse(raw)
|
309
|
+
raw_orig.should == raw
|
310
|
+
addr[:number].should == "167"
|
311
|
+
addr[:direction].should == "W"
|
312
|
+
addr[:street].should == "4th"
|
313
|
+
addr[:type].should == "St."
|
314
|
+
addr[:city].should == "New York"
|
315
|
+
addr[:state].should == "NY"
|
316
|
+
addr[:zipcode].should == "10014"
|
317
|
+
addr[:intersection].should == false
|
77
318
|
end
|
319
|
+
|
78
320
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: normalic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Tang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-26 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Normalize U.S addresses
|
@@ -28,13 +28,19 @@ extra_rdoc_files:
|
|
28
28
|
- README.rdoc
|
29
29
|
- lib/constants.rb
|
30
30
|
- lib/normalic.rb
|
31
|
+
- lib/normalic/address.rb
|
32
|
+
- lib/normalic/phone_number.rb
|
33
|
+
- lib/normalic/uri.rb
|
31
34
|
files:
|
35
|
+
- Manifest
|
32
36
|
- README.rdoc
|
33
37
|
- Rakefile
|
34
38
|
- lib/constants.rb
|
35
39
|
- lib/normalic.rb
|
40
|
+
- lib/normalic/address.rb
|
41
|
+
- lib/normalic/phone_number.rb
|
42
|
+
- lib/normalic/uri.rb
|
36
43
|
- spec/normalic_spec.rb
|
37
|
-
- Manifest
|
38
44
|
- normalic.gemspec
|
39
45
|
homepage: http://github.com/ericxtang/normalic
|
40
46
|
licenses: []
|