street_address 1.0.0

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andrew Stevens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ A port of the GEO::StreetAddress::US Perl Library. http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm
2
+
3
+ =Use it
4
+ >> StreetAddress.parse("123 Fake St. South Chicago, IL, 90210")
5
+ => {"city"=>"Chicago", "number"=>"123", "zip"=>"90210", "prefix"=>"", "street"=>"Fake", "type"=>"St", "suffix"=>"S", "state"=>"IL"}
6
+
7
+ Please feel free to do whatever you'd like with it, and if you find it useful let me know.
8
+
9
+ Cheers,
10
+ Jeremy Hubert
11
+ http://jeremyhubert.com
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "street_address"
8
+ gem.summary = %Q{US Street address parser}
9
+ gem.description = %Q{A Ruby port of the Geo::StreetAddress::US Library, originally by Jeremy Hubert}
10
+ gem.email = "astevens@tstmedia.com"
11
+ gem.homepage = "http://github.com/astevens/street_address"
12
+ gem.authors = ["Andrew Stevens"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "street_address #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,532 @@
1
+ module StreetAddress
2
+
3
+ Directional = {
4
+ "north" => "N",
5
+ "northeast" => "NE",
6
+ "east" => "E",
7
+ "southeast" => "SE",
8
+ "south" => "S",
9
+ "southwest" => "SW",
10
+ "west" => "W",
11
+ "northwest" => "NW"
12
+ }
13
+ Directional_code = Directional.invert
14
+
15
+ StreetTypes = {
16
+ "allee" => "aly",
17
+ "alley" => "aly",
18
+ "ally" => "aly",
19
+ "anex" => "anx",
20
+ "annex" => "anx",
21
+ "annx" => "anx",
22
+ "arcade" => "arc",
23
+ "av" => "ave",
24
+ "aven" => "ave",
25
+ "avenu" => "ave",
26
+ "avenue" => "ave",
27
+ "avn" => "ave",
28
+ "avnue" => "ave",
29
+ "bayoo" => "byu",
30
+ "bayou" => "byu",
31
+ "beach" => "bch",
32
+ "bend" => "bnd",
33
+ "bluf" => "blf",
34
+ "bluff" => "blf",
35
+ "bluffs" => "blfs",
36
+ "bot" => "btm",
37
+ "bottm" => "btm",
38
+ "bottom" => "btm",
39
+ "boul" => "blvd",
40
+ "boulevard" => "blvd",
41
+ "boulv" => "blvd",
42
+ "branch" => "br",
43
+ "brdge" => "brg",
44
+ "bridge" => "brg",
45
+ "brnch" => "br",
46
+ "brook" => "brk",
47
+ "brooks" => "brks",
48
+ "burg" => "bg",
49
+ "burgs" => "bgs",
50
+ "bypa" => "byp",
51
+ "bypas" => "byp",
52
+ "bypass" => "byp",
53
+ "byps" => "byp",
54
+ "camp" => "cp",
55
+ "canyn" => "cyn",
56
+ "canyon" => "cyn",
57
+ "cape" => "cpe",
58
+ "causeway" => "cswy",
59
+ "causway" => "cswy",
60
+ "cen" => "ctr",
61
+ "cent" => "ctr",
62
+ "center" => "ctr",
63
+ "centers" => "ctrs",
64
+ "centr" => "ctr",
65
+ "centre" => "ctr",
66
+ "circ" => "cir",
67
+ "circl" => "cir",
68
+ "circle" => "cir",
69
+ "circles" => "cirs",
70
+ "ck" => "crk",
71
+ "cliff" => "clf",
72
+ "cliffs" => "clfs",
73
+ "club" => "clb",
74
+ "cmp" => "cp",
75
+ "cnter" => "ctr",
76
+ "cntr" => "ctr",
77
+ "cnyn" => "cyn",
78
+ "common" => "cmn",
79
+ "corner" => "cor",
80
+ "corners" => "cors",
81
+ "course" => "crse",
82
+ "court" => "ct",
83
+ "courts" => "cts",
84
+ "cove" => "cv",
85
+ "coves" => "cvs",
86
+ "cr" => "crk",
87
+ "crcl" => "cir",
88
+ "crcle" => "cir",
89
+ "crecent" => "cres",
90
+ "creek" => "crk",
91
+ "crescent" => "cres",
92
+ "cresent" => "cres",
93
+ "crest" => "crst",
94
+ "crossing" => "xing",
95
+ "crossroad" => "xrd",
96
+ "crscnt" => "cres",
97
+ "crsent" => "cres",
98
+ "crsnt" => "cres",
99
+ "crssing" => "xing",
100
+ "crssng" => "xing",
101
+ "crt" => "ct",
102
+ "curve" => "curv",
103
+ "dale" => "dl",
104
+ "dam" => "dm",
105
+ "div" => "dv",
106
+ "divide" => "dv",
107
+ "driv" => "dr",
108
+ "drive" => "dr",
109
+ "drives" => "drs",
110
+ "drv" => "dr",
111
+ "dvd" => "dv",
112
+ "estate" => "est",
113
+ "estates" => "ests",
114
+ "exp" => "expy",
115
+ "expr" => "expy",
116
+ "express" => "expy",
117
+ "expressway" => "expy",
118
+ "expw" => "expy",
119
+ "extension" => "ext",
120
+ "extensions" => "exts",
121
+ "extn" => "ext",
122
+ "extnsn" => "ext",
123
+ "falls" => "fls",
124
+ "ferry" => "fry",
125
+ "field" => "fld",
126
+ "fields" => "flds",
127
+ "flat" => "flt",
128
+ "flats" => "flts",
129
+ "ford" => "frd",
130
+ "fords" => "frds",
131
+ "forest" => "frst",
132
+ "forests" => "frst",
133
+ "forg" => "frg",
134
+ "forge" => "frg",
135
+ "forges" => "frgs",
136
+ "fork" => "frk",
137
+ "forks" => "frks",
138
+ "fort" => "ft",
139
+ "freeway" => "fwy",
140
+ "freewy" => "fwy",
141
+ "frry" => "fry",
142
+ "frt" => "ft",
143
+ "frway" => "fwy",
144
+ "frwy" => "fwy",
145
+ "garden" => "gdn",
146
+ "gardens" => "gdns",
147
+ "gardn" => "gdn",
148
+ "gateway" => "gtwy",
149
+ "gatewy" => "gtwy",
150
+ "gatway" => "gtwy",
151
+ "glen" => "gln",
152
+ "glens" => "glns",
153
+ "grden" => "gdn",
154
+ "grdn" => "gdn",
155
+ "grdns" => "gdns",
156
+ "green" => "grn",
157
+ "greens" => "grns",
158
+ "grov" => "grv",
159
+ "grove" => "grv",
160
+ "groves" => "grvs",
161
+ "gtway" => "gtwy",
162
+ "harb" => "hbr",
163
+ "harbor" => "hbr",
164
+ "harbors" => "hbrs",
165
+ "harbr" => "hbr",
166
+ "haven" => "hvn",
167
+ "havn" => "hvn",
168
+ "height" => "hts",
169
+ "heights" => "hts",
170
+ "hgts" => "hts",
171
+ "highway" => "hwy",
172
+ "highwy" => "hwy",
173
+ "hill" => "hl",
174
+ "hills" => "hls",
175
+ "hiway" => "hwy",
176
+ "hiwy" => "hwy",
177
+ "hllw" => "holw",
178
+ "hollow" => "holw",
179
+ "hollows" => "holw",
180
+ "holws" => "holw",
181
+ "hrbor" => "hbr",
182
+ "ht" => "hts",
183
+ "hway" => "hwy",
184
+ "inlet" => "inlt",
185
+ "island" => "is",
186
+ "islands" => "iss",
187
+ "isles" => "isle",
188
+ "islnd" => "is",
189
+ "islnds" => "iss",
190
+ "jction" => "jct",
191
+ "jctn" => "jct",
192
+ "jctns" => "jcts",
193
+ "junction" => "jct",
194
+ "junctions" => "jcts",
195
+ "junctn" => "jct",
196
+ "juncton" => "jct",
197
+ "key" => "ky",
198
+ "keys" => "kys",
199
+ "knol" => "knl",
200
+ "knoll" => "knl",
201
+ "knolls" => "knls",
202
+ "la" => "ln",
203
+ "lake" => "lk",
204
+ "lakes" => "lks",
205
+ "landing" => "lndg",
206
+ "lane" => "ln",
207
+ "lanes" => "ln",
208
+ "ldge" => "ldg",
209
+ "light" => "lgt",
210
+ "lights" => "lgts",
211
+ "lndng" => "lndg",
212
+ "loaf" => "lf",
213
+ "lock" => "lck",
214
+ "locks" => "lcks",
215
+ "lodg" => "ldg",
216
+ "lodge" => "ldg",
217
+ "loops" => "loop",
218
+ "manor" => "mnr",
219
+ "manors" => "mnrs",
220
+ "meadow" => "mdw",
221
+ "meadows" => "mdws",
222
+ "medows" => "mdws",
223
+ "mill" => "ml",
224
+ "mills" => "mls",
225
+ "mission" => "msn",
226
+ "missn" => "msn",
227
+ "mnt" => "mt",
228
+ "mntain" => "mtn",
229
+ "mntn" => "mtn",
230
+ "mntns" => "mtns",
231
+ "motorway" => "mtwy",
232
+ "mount" => "mt",
233
+ "mountain" => "mtn",
234
+ "mountains" => "mtns",
235
+ "mountin" => "mtn",
236
+ "mssn" => "msn",
237
+ "mtin" => "mtn",
238
+ "neck" => "nck",
239
+ "orchard" => "orch",
240
+ "orchrd" => "orch",
241
+ "overpass" => "opas",
242
+ "ovl" => "oval",
243
+ "parks" => "park",
244
+ "parkway" => "pkwy",
245
+ "parkways" => "pkwy",
246
+ "parkwy" => "pkwy",
247
+ "passage" => "psge",
248
+ "paths" => "path",
249
+ "pikes" => "pike",
250
+ "pine" => "pne",
251
+ "pines" => "pnes",
252
+ "pk" => "park",
253
+ "pkway" => "pkwy",
254
+ "pkwys" => "pkwy",
255
+ "pky" => "pkwy",
256
+ "place" => "pl",
257
+ "plain" => "pln",
258
+ "plaines" => "plns",
259
+ "plains" => "plns",
260
+ "plaza" => "plz",
261
+ "plza" => "plz",
262
+ "point" => "pt",
263
+ "points" => "pts",
264
+ "port" => "prt",
265
+ "ports" => "prts",
266
+ "prairie" => "pr",
267
+ "prarie" => "pr",
268
+ "prk" => "park",
269
+ "prr" => "pr",
270
+ "rad" => "radl",
271
+ "radial" => "radl",
272
+ "radiel" => "radl",
273
+ "ranch" => "rnch",
274
+ "ranches" => "rnch",
275
+ "rapid" => "rpd",
276
+ "rapids" => "rpds",
277
+ "rdge" => "rdg",
278
+ "rest" => "rst",
279
+ "ridge" => "rdg",
280
+ "ridges" => "rdgs",
281
+ "river" => "riv",
282
+ "rivr" => "riv",
283
+ "rnchs" => "rnch",
284
+ "road" => "rd",
285
+ "roads" => "rds",
286
+ "route" => "rte",
287
+ "rvr" => "riv",
288
+ "shoal" => "shl",
289
+ "shoals" => "shls",
290
+ "shoar" => "shr",
291
+ "shoars" => "shrs",
292
+ "shore" => "shr",
293
+ "shores" => "shrs",
294
+ "skyway" => "skwy",
295
+ "spng" => "spg",
296
+ "spngs" => "spgs",
297
+ "spring" => "spg",
298
+ "springs" => "spgs",
299
+ "sprng" => "spg",
300
+ "sprngs" => "spgs",
301
+ "spurs" => "spur",
302
+ "sqr" => "sq",
303
+ "sqre" => "sq",
304
+ "sqrs" => "sqs",
305
+ "squ" => "sq",
306
+ "square" => "sq",
307
+ "squares" => "sqs",
308
+ "station" => "sta",
309
+ "statn" => "sta",
310
+ "stn" => "sta",
311
+ "str" => "st",
312
+ "strav" => "stra",
313
+ "strave" => "stra",
314
+ "straven" => "stra",
315
+ "stravenue" => "stra",
316
+ "stravn" => "stra",
317
+ "stream" => "strm",
318
+ "street" => "st",
319
+ "streets" => "sts",
320
+ "streme" => "strm",
321
+ "strt" => "st",
322
+ "strvn" => "stra",
323
+ "strvnue" => "stra",
324
+ "sumit" => "smt",
325
+ "sumitt" => "smt",
326
+ "summit" => "smt",
327
+ "terr" => "ter",
328
+ "terrace" => "ter",
329
+ "throughway" => "trwy",
330
+ "tpk" => "tpke",
331
+ "tr" => "trl",
332
+ "trace" => "trce",
333
+ "traces" => "trce",
334
+ "track" => "trak",
335
+ "tracks" => "trak",
336
+ "trafficway" => "trfy",
337
+ "trail" => "trl",
338
+ "trails" => "trl",
339
+ "trk" => "trak",
340
+ "trks" => "trak",
341
+ "trls" => "trl",
342
+ "trnpk" => "tpke",
343
+ "trpk" => "tpke",
344
+ "tunel" => "tunl",
345
+ "tunls" => "tunl",
346
+ "tunnel" => "tunl",
347
+ "tunnels" => "tunl",
348
+ "tunnl" => "tunl",
349
+ "turnpike" => "tpke",
350
+ "turnpk" => "tpke",
351
+ "underpass" => "upas",
352
+ "union" => "un",
353
+ "unions" => "uns",
354
+ "valley" => "vly",
355
+ "valleys" => "vlys",
356
+ "vally" => "vly",
357
+ "vdct" => "via",
358
+ "viadct" => "via",
359
+ "viaduct" => "via",
360
+ "view" => "vw",
361
+ "views" => "vws",
362
+ "vill" => "vlg",
363
+ "villag" => "vlg",
364
+ "village" => "vlg",
365
+ "villages" => "vlgs",
366
+ "ville" => "vl",
367
+ "villg" => "vlg",
368
+ "villiage" => "vlg",
369
+ "vist" => "vis",
370
+ "vista" => "vis",
371
+ "vlly" => "vly",
372
+ "vst" => "vis",
373
+ "vsta" => "vis",
374
+ "walks" => "walk",
375
+ "well" => "wl",
376
+ "wells" => "wls",
377
+ "wy" => "way"
378
+ }
379
+ StreetTypes_list = StreetTypes.to_a.flatten.uniq
380
+
381
+ StateCodes = {
382
+ "alabama" => "AL",
383
+ "alaska" => "AK",
384
+ "american samoa" => "AS",
385
+ "arizona" => "AZ",
386
+ "arkansas" => "AR",
387
+ "california" => "CA",
388
+ "colorado" => "CO",
389
+ "connecticut" => "CT",
390
+ "delaware" => "DE",
391
+ "district of columbia" => "DC",
392
+ "federated states of micronesia" => "FM",
393
+ "florida" => "FL",
394
+ "georgia" => "GA",
395
+ "guam" => "GU",
396
+ "hawaii" => "HI",
397
+ "idaho" => "ID",
398
+ "illinois" => "IL",
399
+ "indiana" => "IN",
400
+ "iowa" => "IA",
401
+ "kansas" => "KS",
402
+ "kentucky" => "KY",
403
+ "louisiana" => "LA",
404
+ "maine" => "ME",
405
+ "marshall islands" => "MH",
406
+ "maryland" => "MD",
407
+ "massachusetts" => "MA",
408
+ "michigan" => "MI",
409
+ "minnesota" => "MN",
410
+ "mississippi" => "MS",
411
+ "missouri" => "MO",
412
+ "montana" => "MT",
413
+ "nebraska" => "NE",
414
+ "nevada" => "NV",
415
+ "new hampshire" => "NH",
416
+ "new jersey" => "NJ",
417
+ "new mexico" => "NM",
418
+ "new york" => "NY",
419
+ "north carolina" => "NC",
420
+ "north dakota" => "ND",
421
+ "northern mariana islands" => "MP",
422
+ "ohio" => "OH",
423
+ "oklahoma" => "OK",
424
+ "oregon" => "OR",
425
+ "palau" => "PW",
426
+ "pennsylvania" => "PA",
427
+ "puerto rico" => "PR",
428
+ "rhode island" => "RI",
429
+ "south carolina" => "SC",
430
+ "south dakota" => "SD",
431
+ "tennessee" => "TN",
432
+ "texas" => "TX",
433
+ "utah" => "UT",
434
+ "vermont" => "VT",
435
+ "virgin islands" => "VI",
436
+ "virginia" => "VA",
437
+ "washington" => "WA",
438
+ "west virginia" => "WV",
439
+ "wisconsin" => "WI",
440
+ "wyoming" => "WY",
441
+ "alberta" => "AB",
442
+ "british columbia" => "BC",
443
+ "newfoundland and labrador" => "NL",
444
+ "nova scotia" => "NS",
445
+ "prince edward island" => "PE",
446
+ "new brunswick" => "NB",
447
+ "quebec" => "QC",
448
+ "ontario" => "ON",
449
+ "manitoba" => "MB",
450
+ "saskatchewan" => "SK",
451
+ "nunavut" => "NU",
452
+ "northwest territories" => "NT",
453
+ "yukon territory" => "YT"
454
+ }
455
+ StateCodes_key = StateCodes.map{|k,v| [v, k]}
456
+
457
+ RegExs = {
458
+ "type" => Regexp.new(StreetTypes_list * '|',Regexp::IGNORECASE),
459
+ "number" => /\d+-?\d*/,
460
+ "fraction" => /\d+\/\d+/,
461
+ "state" => Regexp.new(StateCodes.values * '|' + '|' + StateCodes.keys * '|',Regexp::IGNORECASE),
462
+ "direct" => Regexp.new(Directional.keys * '|' + '|' + Directional.values * '\.?|',Regexp::IGNORECASE),
463
+ "dircode" => Regexp.new(Directional_code.keys * '\.?|',Regexp::IGNORECASE),
464
+ "zip" => /((?:\d{5}(?:-\d{4})?)|(?:\w\d\w\s?\d\w\d))?/i,
465
+ "unit" => /(?:(?:su?i?te|p\W*[om]\W*b(?:ox)?|dept|apt|ro*m|fl|apt|unit|box)\W+|\#\W*)[\w-]+/i,
466
+ "corner" => /(?:\band\b|\bat\b|&|\@)/i
467
+ }
468
+
469
+ RegExs["place"] = Regexp.new('(?:([^\d,]+?)\W+ ('+RegExs['state'].to_s+')\W*)? '+RegExs['zip'].to_s+'',Regexp::IGNORECASE)
470
+
471
+ RegExs["street"] = Regexp.new('(?:(?:(' + RegExs['direct'].to_s + ')\W+ (' + RegExs['type'].to_s + ')\b )|(?:(' + RegExs['direct'].to_s + ')\W+ )?(?:([^,]+)(?:[^\w,]+(' + RegExs['type'].to_s + ')\b )(?:[^\w,]+(' + RegExs['direct'].to_s + ')\b )?|([^,]*\d)(' + RegExs['direct'].to_s + ')\b|([^,]+?)(?:[^\w,]+(' + RegExs['type'].to_s + ')\b )?(?:[^\w,]+(' + RegExs['direct'].to_s + ')\b )?))',Regexp::IGNORECASE)
472
+
473
+ RegExs["address"] = Regexp.new('^\W*(' + RegExs['number'].to_s + ')\W*(?:' + RegExs['fraction'].to_s + '\W*)?' + RegExs['street'].source + '\W+(?:' + RegExs['unit'].to_s + '\W+)?' + RegExs['place'].source + '\W*$',Regexp::EXTENDED)
474
+
475
+ NormalizeMap = {
476
+ 'prefix' => Directional,
477
+ 'prefix1' => Directional,
478
+ 'prefix2' => Directional,
479
+ 'suffix' => Directional,
480
+ 'suffix1' => Directional,
481
+ 'suffix2' => Directional,
482
+ 'type' => StreetTypes,
483
+ 'type1' => StreetTypes,
484
+ 'type2' => StreetTypes,
485
+ 'state' => StateCodes,
486
+ }
487
+
488
+ def StreetAddress.output
489
+ RegExs["address"].to_s
490
+ end
491
+
492
+ def StreetAddress.parse(address)
493
+ result = RegExs["address"].match(address).to_a
494
+ if result.nil?
495
+ return false
496
+ else
497
+ result.shift
498
+ return StreetAddress.normalize(result)
499
+ end
500
+
501
+ end
502
+
503
+ def StreetAddress.normalize(result)
504
+
505
+ result.map { |x| x.gsub!(/^\s+|\s+$|[^\w\s\-]/s,'') unless x.nil? }
506
+
507
+ address = {
508
+ 'number' => result[0].to_s,
509
+ 'prefix' => result[3].to_s,
510
+ 'street' => result[4].to_s,
511
+ 'type' => result[5].to_s,
512
+ 'suffix' => result[6].to_s,
513
+ 'city' => result[12].to_s,
514
+ 'state' => result[13].to_s,
515
+ 'zip' => result[14].to_s
516
+ }
517
+
518
+ NormalizeMap.map do | k,v |
519
+ if !address[k].nil?
520
+ address[k] = v[address[k].downcase] if !v[address[k].downcase].nil?
521
+ end
522
+ end
523
+
524
+ # Expand 'S. Vancouver' to 'South Vancouver', I think. Commented out until I understand it.
525
+ # address['city'].gsub!(Regexp.new('^('+RegExs['dircode'].to_s+')\s+(?=\S)'),Directional_code['\1.downcase']) if address['city']
526
+
527
+ address['zip'].gsub!(/-.*$/s,'') if address['zip']
528
+
529
+ address
530
+ end
531
+
532
+ end
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{street_address}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew Stevens"]
12
+ s.date = %q{2010-09-13}
13
+ s.description = %q{A Ruby port of the Geo::StreetAddress::US Library, originally by Jeremy Hubert}
14
+ s.email = %q{astevens@tstmedia.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/street_address.rb",
27
+ "street_address.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_street_address.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/astevens/street_address}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{US Street address parser}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_street_address.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'street_address'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestStreetAddress < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: street_address
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Stevens
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-13 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: A Ruby port of the Geo::StreetAddress::US Library, originally by Jeremy Hubert
36
+ email: astevens@tstmedia.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/street_address.rb
52
+ - street_address.gemspec
53
+ - test/helper.rb
54
+ - test/test_street_address.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/astevens/street_address
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: US Street address parser
89
+ test_files:
90
+ - test/helper.rb
91
+ - test/test_street_address.rb