people_places_things 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.textile +3 -1
- data/lib/people_places_things/street_address.rb +299 -66
- data/lib/people_places_things/version.rb +3 -0
- data/lib/people_places_things.rb +1 -4
- metadata +40 -43
- data/.gitignore +0 -3
- data/Rakefile +0 -42
- data/lib/people_places_things/VERSION +0 -1
- data/people_places_things.gemspec +0 -70
- data/spec/ansi_counties_spec.rb +0 -27
- data/spec/helper.rb +0 -2
- data/spec/location_spec.rb +0 -56
- data/spec/person_name_spec.rb +0 -195
- data/spec/phone_number_spec.rb +0 -63
- data/spec/state_spec.rb +0 -33
- data/spec/street_address_spec.rb +0 -163
- data/spec/zip_code_spec.rb +0 -31
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Danny Burkes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
CHANGED
@@ -65,4 +65,6 @@ h2. Data source
|
|
65
65
|
|
66
66
|
The data that makes up @lib/people_places_things/data/data.yml@ was generated from @lib/people_places_things/data/raw.txt@, which was downloaded from "the US Census website":http://www.census.gov/geo/www/ansi/download.html.
|
67
67
|
|
68
|
-
|
68
|
+
h2. License
|
69
|
+
|
70
|
+
SUID is released under the MIT License
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module PeoplePlacesThings
|
2
2
|
class StreetAddress
|
3
|
-
attr_accessor :number, :pre_direction, :name, :suffix, :post_direction, :unit_type, :unit, :raw
|
3
|
+
attr_accessor :number, :pre_direction, :ordinal, :name, :suffix, :post_direction, :unit_type, :unit, :box_number, :raw
|
4
4
|
|
5
5
|
def initialize(str)
|
6
6
|
self.raw = str
|
@@ -20,9 +20,15 @@ module PeoplePlacesThings
|
|
20
20
|
if self.unit_type
|
21
21
|
self.unit = tokens[-1]
|
22
22
|
tokens.slice!(tokens.size - 2, 2)
|
23
|
+
if tokens.size > 0
|
24
|
+
# see if unit_type is specified twice i.e. Suite #
|
25
|
+
if StreetAddress.find_token(tokens[-1], UNIT_TYPES)
|
26
|
+
tokens.slice!(tokens.size - 1)
|
27
|
+
end
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
|
-
|
31
|
+
|
26
32
|
# If at least one token remains, check last token for directionality. If so, set post_direction and delete the token
|
27
33
|
#
|
28
34
|
if tokens.size > 0
|
@@ -33,7 +39,7 @@ module PeoplePlacesThings
|
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
|
-
# If at least one token remains, check last token for suffix. If so,
|
42
|
+
# If at least one token remains, check last token for suffix. If so, set suffix and delete the token
|
37
43
|
#
|
38
44
|
if tokens.size > 0
|
39
45
|
self.suffix = StreetAddress.find_token(tokens[-1], SUFFIXES)
|
@@ -47,8 +53,20 @@ module PeoplePlacesThings
|
|
47
53
|
tokens.shift if self.pre_direction
|
48
54
|
end
|
49
55
|
|
50
|
-
#
|
56
|
+
# If at least one token remains, check for ordinal
|
57
|
+
#
|
58
|
+
if tokens.size > 0
|
59
|
+
self.ordinal = tokens.first if StreetAddress.find_token(tokens.first, ORDINALS)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Check for a PO Box / Rural Route pattern and extract the box_number
|
51
63
|
#
|
64
|
+
if tokens.size > 2 && self.number == nil && (tokens.join(' ') =~ PO_BOX_PATTERN || tokens.join(' ') =~ RR_PATTERN)
|
65
|
+
self.box_number = tokens[-1].gsub(/[(,?!\'":.#)]/, '')
|
66
|
+
end
|
67
|
+
|
68
|
+
# if any tokens remain, set joined remaining tokens as name, otherwise, set name to post_direction, if set, and set post_direction to nil
|
69
|
+
#
|
52
70
|
if tokens.size > 0
|
53
71
|
self.name = tokens.join(' ')
|
54
72
|
else
|
@@ -59,6 +77,11 @@ module PeoplePlacesThings
|
|
59
77
|
validate_parts
|
60
78
|
end
|
61
79
|
|
80
|
+
# check for a valid street address, we assume at least a number or box_number and name is required.
|
81
|
+
def valid?
|
82
|
+
!self.name.nil? && !(self.number.nil? && self.box_number.nil?)
|
83
|
+
end
|
84
|
+
|
62
85
|
def to_s
|
63
86
|
parts = []
|
64
87
|
parts << self.number if self.number
|
@@ -70,11 +93,34 @@ module PeoplePlacesThings
|
|
70
93
|
parts << self.unit if self.unit
|
71
94
|
parts.join(' ')
|
72
95
|
end
|
96
|
+
|
97
|
+
# to_canonical_s
|
98
|
+
# format the address in a postal service canonical format
|
99
|
+
def to_canonical_s
|
100
|
+
parts = []
|
101
|
+
parts << self.number.upcase if self.number
|
102
|
+
parts << StreetAddress.string_for(self.pre_direction, :short).upcase if self.pre_direction
|
103
|
+
parts << StreetAddress.string_for(StreetAddress.find_token(self.ordinal, ORDINALS), :short).upcase if self.ordinal
|
104
|
+
canonical_name = self.name.gsub(/[(,?!\'":.#)]/, '').gsub(PO_BOX_PATTERN, 'PO BOX').upcase if self.name
|
105
|
+
canonical_name.gsub!(/(rr|r.r.)/i, 'RR') if canonical_name =~ RR_PATTERN
|
106
|
+
# remove the original ordinal and box from the name, they are output in canonical form separately
|
107
|
+
canonical_name.gsub!(self.ordinal.upcase, '') if self.ordinal
|
108
|
+
canonical_name.gsub!(self.box_number, '') if self.box_number
|
109
|
+
parts << canonical_name.chomp(' ') if canonical_name
|
110
|
+
parts << self.box_number if self.box_number
|
111
|
+
parts << StreetAddress.string_for(self.suffix, :short).upcase if self.suffix
|
112
|
+
parts << StreetAddress.string_for(self.post_direction, :short).upcase if self.post_direction
|
113
|
+
# make all unit type as the canoncial number "#"
|
114
|
+
parts << StreetAddress.string_for(:number, :short).upcase if self.unit_type
|
115
|
+
parts << self.unit.upcase if self.unit
|
116
|
+
parts.delete('')
|
117
|
+
parts.join(' ')
|
118
|
+
end
|
73
119
|
|
74
120
|
def self.string_for(symbol, form)
|
75
121
|
raise "Requested unknown form \"#{type}\" for :#{symbol}" if !SUPPORTED_FORMS.include?(form)
|
76
122
|
|
77
|
-
val = DIRECTIONS[symbol] || SUFFIXES[symbol] || UNIT_TYPES[symbol]
|
123
|
+
val = DIRECTIONS[symbol] || SUFFIXES[symbol] || UNIT_TYPES[symbol] || ORDINALS[symbol]
|
78
124
|
|
79
125
|
if val
|
80
126
|
val = ((val[SUPPORTED_FORMS.index(form)] rescue nil) || (val.first rescue val))
|
@@ -102,80 +148,267 @@ module PeoplePlacesThings
|
|
102
148
|
nil
|
103
149
|
end
|
104
150
|
|
151
|
+
PO_BOX_PATTERN = /(p.o. box|p o box|post office box|po box)/i
|
152
|
+
RR_PATTERN = /(rr|r.r.)\s*(#\d+|\d+)(\s*-\s*|\s*)box(\s*|\s*-\s*)(#\d+|\d+)/i
|
153
|
+
|
154
|
+
# to_canonical_s uses the short version of each of the following
|
155
|
+
# long version is in position 0
|
156
|
+
# short version is in position 1
|
157
|
+
|
105
158
|
DIRECTIONS = {
|
106
|
-
:north
|
159
|
+
:north => %w(north n n.),
|
107
160
|
:northeast => %w(northeast ne ne. n.e.),
|
108
|
-
:east
|
161
|
+
:east => %w(east e e.),
|
109
162
|
:southeast => %w(southeast se se. s.e.),
|
110
|
-
:south
|
163
|
+
:south => %w(south s s.),
|
111
164
|
:southwest => %w(southwest sw sw. s.w.),
|
112
|
-
:west
|
165
|
+
:west => %w(west w w.),
|
113
166
|
:northwest => %w(northwest nw nw. n.w.)
|
167
|
+
|
114
168
|
}
|
115
169
|
|
116
170
|
SUFFIXES = {
|
117
|
-
:alley
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
+
:alley => %w(alley aly ally allee al al.),
|
172
|
+
:anex => %w(anex anx annex annx anx.),
|
173
|
+
:arcade => %w(arcade arc arc.),
|
174
|
+
:avenue => %w(avenue ave aven avenu avnue ave. av av.),
|
175
|
+
:bayou => %w(bayou byu bayoo byu.),
|
176
|
+
:beach => %w(beach bch bch.),
|
177
|
+
:bend => %w(bend bnd bnd.),
|
178
|
+
:bluff => %w(bluff blf bluf blf.),
|
179
|
+
:bluffs => %w(bluffs blfs blfs.),
|
180
|
+
:bottom => %w(bottom btm bot bottm btm.),
|
181
|
+
:boulevard => %w(boulevard blvd blvd. boul boulv blv blv.),
|
182
|
+
:branch => %w(branch br brnch br.),
|
183
|
+
:bridge => %w(bridge brg brdge),
|
184
|
+
:brook => %w(brook brk brk.),
|
185
|
+
:brooks => %w(brooks brks),
|
186
|
+
:burg => %w(burg bg),
|
187
|
+
:burgs => %w(burgs bgs),
|
188
|
+
:bypass => %w(bypass byp bypa bypas byps),
|
189
|
+
:camp => %w(camp cp cmp),
|
190
|
+
:canyon => %w(canyon cyn canyn cnyn cyn.),
|
191
|
+
:cape => %w(cape cpe),
|
192
|
+
:causeway => %w(causeway cswy causwa cswy.),
|
193
|
+
:center => %w(center ctr cent centr cnter centre cntr ctr.),
|
194
|
+
:centers => %w(centers ctrs),
|
195
|
+
:circle => %w(circle cir circ circl crcl crcle cir.),
|
196
|
+
:cliff => %w(cliff clf clf.),
|
197
|
+
:cliffs => %w(cliffs clfs),
|
198
|
+
:club => %w(club clb),
|
199
|
+
:common => %w(common cmn),
|
200
|
+
:commons => %w(commons cmns),
|
201
|
+
:corner => %w(corner cor),
|
202
|
+
:corners => %w(corners cors),
|
203
|
+
:condo => %w(condo con con.),
|
204
|
+
:court => %w(court ct ct. cor cor.),
|
205
|
+
:courts => %w(courts cts cts.),
|
206
|
+
:cove => %w(cove cv),
|
207
|
+
:coves => %w(coves cvs),
|
208
|
+
:creek => %w(creek crk crk.),
|
209
|
+
:crescent => %w(crescent cres crsent crsnt),
|
210
|
+
:crest => %w(crest crst),
|
211
|
+
:crossing => %w(crossing xing xing. crssng crs crs.),
|
212
|
+
:crossroad => %w(crossroad xrd),
|
213
|
+
:crossroads => %w(crossroads xrds),
|
214
|
+
:curve => %w(curve curv),
|
215
|
+
:dale => %w(dale dl),
|
216
|
+
:dam => %w(dam dm),
|
217
|
+
:divide => %w(divide dv div dvd),
|
218
|
+
:drive => %w(drive dr driv drv dr.),
|
219
|
+
:drives => %w(drives drs),
|
220
|
+
:estate => %w(estate est),
|
221
|
+
:estates => %w(estates ests),
|
222
|
+
:expressway => %w(expressway expy exp expr express expw expr),
|
223
|
+
:extension => %w(extension ext ext.),
|
224
|
+
:extensions => %w(extensions exts),
|
225
|
+
:fall => %w(fall fall),
|
226
|
+
:falls => %w(falls fls),
|
227
|
+
:ferry => %w(ferry fry frry),
|
228
|
+
:field => %w(field fld),
|
229
|
+
:fields => %w(fields flds),
|
230
|
+
:flat => %w(flat flt),
|
231
|
+
:flats => %w(flats flts),
|
232
|
+
:ford => %w(ford, frd),
|
233
|
+
:fords => %w(fords frds),
|
234
|
+
:forest => %w(forest frst forests),
|
235
|
+
:forge => %w(forge frg forg),
|
236
|
+
:forges => %w(forges frgs),
|
237
|
+
:fork => %w(fork frk),
|
238
|
+
:forks => %w(forks frks),
|
239
|
+
:fort => %w(fort ft frt),
|
240
|
+
:freeway => %w(freeway fwy freewy frway fwy.),
|
241
|
+
:garden => %w(garden gdn gardn grden grdn),
|
242
|
+
:gardens => %w(gardens gdns gdns.),
|
243
|
+
:gateway => %w(gateway gtwy gatewy gatway gtway),
|
244
|
+
:glen => %w(glen gln gl gl.),
|
245
|
+
:glens => %w(glens glns),
|
246
|
+
:green => %w(green grn grn.),
|
247
|
+
:greens => %w(greens grns),
|
248
|
+
:grove => %w(grove grv grov),
|
249
|
+
:groves => %w(groves grvs),
|
250
|
+
:harbor => %w(harbor hbr harb harbr hrbor),
|
251
|
+
:harbors => %w(harbors hbrs),
|
252
|
+
:haven => %w(haven hvn),
|
253
|
+
:heights => %w(heights hts hts.),
|
254
|
+
:highway => %w(highway hwy highwy hiway hiwy hway hwy. hgwy hgwy.),
|
255
|
+
:hill => %w(hill hl),
|
256
|
+
:hills => %w(hills hls),
|
257
|
+
:hollow => %w(hollow holw hllw hollows holw holws),
|
258
|
+
:inlet => %w(inlet inlt),
|
259
|
+
:island => %w(island is islnd),
|
260
|
+
:islands => %w(islands iss islnds),
|
261
|
+
:isle => %w(isle isle isles),
|
262
|
+
:junction => %w(junction jct jction jctn junctn juncton),
|
263
|
+
:junctions => %w(junctions jcts jctns),
|
264
|
+
:key => %w(key ky),
|
265
|
+
:keys => %w(keys kys),
|
266
|
+
:knoll => %w(knoll knl knl.),
|
267
|
+
:knolls => %w(knolls knls),
|
268
|
+
:lake => %w(lake lk),
|
269
|
+
:lakes => %w(lakes lks),
|
270
|
+
:land => %w(land land),
|
271
|
+
:landing => %w(landing lndg lndg.),
|
272
|
+
:lane => %w(lane ln ln.),
|
273
|
+
:light => %w(light lgt),
|
274
|
+
:lights => %w(lights lgts),
|
275
|
+
:loaf => %w(loaf lf),
|
276
|
+
:lock => %w(lock lck),
|
277
|
+
:locks => %w(locks lcks),
|
278
|
+
:lodge => %w(lodge ldg ldge lodg),
|
279
|
+
:loop => %w(loop loop loops),
|
280
|
+
:mall => %w(mall mall),
|
281
|
+
:manor => %w(manor mnr),
|
282
|
+
:manors => %w(manors mnrs),
|
283
|
+
:meadow => %w(meadow mdw),
|
284
|
+
:meadows => %w(meadows mdws medows mdws.),
|
285
|
+
:mews => %w(mews mews),
|
286
|
+
:mill => %w(mill ml),
|
287
|
+
:mills => %w(mills mls),
|
288
|
+
:mission => %w(mission msn missn),
|
289
|
+
:motorway => %w(motorway mtwy),
|
290
|
+
:mount => %w(mount mt mnt),
|
291
|
+
:mountain => %w(mountain mtn mntn mountin mtn. mnt mnt.),
|
292
|
+
:mountains => %w(mountains mtns),
|
293
|
+
:neck => %w(neck nck),
|
294
|
+
:orchard => %w(orchard orch orchrd),
|
295
|
+
:oaks => %w(oaks),
|
296
|
+
:oval => %w(oval oval ovl),
|
297
|
+
:overpass => %w(overpass opas),
|
298
|
+
:park => %w(park park pk. prk prk.),
|
299
|
+
:parkway => %w(parkway pkwy pkwy. pky pky.),
|
300
|
+
:parkways => %w(parkways pkwy pkwys),
|
301
|
+
:pass => %w(pass pass),
|
302
|
+
:passage => %w(passage psge),
|
303
|
+
:path => %w(path path paths),
|
304
|
+
:pike => %w(pike pike pikes),
|
305
|
+
:pine => %w(pine pne),
|
306
|
+
:pines => %w(pines pnes),
|
307
|
+
:pier => %w(pier),
|
308
|
+
:place => %w(place pl pl.),
|
309
|
+
:plain => %w(plain pln),
|
310
|
+
:plains => %w(plains plns),
|
311
|
+
:plaza => %w(plaza plz plza plz.),
|
312
|
+
:point => %w(point pt pt. pnt pnt.),
|
313
|
+
:points => %w(points pts),
|
314
|
+
:port => %w(port prt),
|
315
|
+
:ports => %w(ports prts),
|
316
|
+
:prairie => %w(prairie pr prarie),
|
317
|
+
:radial => %w(radial radl rad radiel),
|
318
|
+
:ramp => %w(ramp ramp),
|
319
|
+
:ranch => %w(ranch rnch ranches rnchs),
|
320
|
+
:rapid => %w(rapid rpd),
|
321
|
+
:rapids => %w(rapids rpds),
|
322
|
+
:rest => %w(rest rst),
|
323
|
+
:ridge => %w(ridge rdg rdge ri.),
|
324
|
+
:ridges => %w(ridges rdgs),
|
325
|
+
:river => %w(river riv rvr),
|
326
|
+
:road => %w(road rd rd.),
|
327
|
+
:roads => %w(roads rds),
|
328
|
+
:route => %w(route rte),
|
329
|
+
:row => %w(row row),
|
330
|
+
:rue => %w(rue rue),
|
331
|
+
:run => %w(run run),
|
332
|
+
:shoal => %w(shoal shl),
|
333
|
+
:shoals => %w(shoals shls),
|
334
|
+
:shore => %w(shore shr shoar),
|
335
|
+
:skyway => %w(skyway skwy),
|
336
|
+
:spring => %w(spring spg spng sprng),
|
337
|
+
:springs => %w(springs spgs spgs.),
|
338
|
+
:spur => %w(spur spur spurs),
|
339
|
+
:square => %w(square sq sqr sqre squ sq.),
|
340
|
+
:squares => %w(squares sqs sqrs),
|
341
|
+
:station => %w(station sta sta.),
|
342
|
+
:stravenue => %w(stravenue stra strav straven stravn strvnue),
|
343
|
+
:stream => %w(stream strm steme),
|
344
|
+
:street => %w(street st strt str st.),
|
345
|
+
:streets => %w(streets sts),
|
346
|
+
:summit => %w(summit smt sumit sumitt),
|
347
|
+
:terrace => %w(terrace ter ter. te te.),
|
348
|
+
:throughway => %w(throughway trwy),
|
349
|
+
:trace => %w(trace trce traces),
|
350
|
+
:track => %w(track trak tracks trk trks),
|
351
|
+
:trafficway => %w(trafficway trfy),
|
352
|
+
:trail => %w(trail trl trails trls trl. tl tl.),
|
353
|
+
:trailer => %w(trailer trlr trlrs),
|
354
|
+
:tunnel => %w(tunnel tunl tunls tunnels tunnl),
|
355
|
+
:turnpike => %w(turnpike tpke turnpk trnpk tpke.),
|
356
|
+
:underpass => %w(underpass upas),
|
357
|
+
:union => %w(union un),
|
358
|
+
:valley => %w(valley vly vlly vally vly.),
|
359
|
+
:valleys => %w(valleys vlys),
|
360
|
+
:viaduct => %w(viaduct via vdct viadct),
|
361
|
+
:view => %w(view vw),
|
362
|
+
:views => %w(views vws),
|
363
|
+
:village => %w(village vlg vill villg villiage vlg),
|
364
|
+
:villages => %w(villages vlgs),
|
365
|
+
:ville => %w(ville vl),
|
366
|
+
:vista => %w(vista vs vis vist vst vsta),
|
367
|
+
:walk => %w(walk walk walks),
|
368
|
+
:wall => %w(wall wall),
|
369
|
+
:way => %w(way way wy),
|
370
|
+
:ways => %w(ways ways),
|
371
|
+
:well => %w(well wl),
|
372
|
+
:wells => %w(wells wls)
|
373
|
+
|
171
374
|
}
|
172
375
|
|
173
376
|
UNIT_TYPES = {
|
174
|
-
:suite
|
175
|
-
:number
|
176
|
-
:apartment
|
377
|
+
:suite => %w(suite ste ste.),
|
378
|
+
:number => %w(number # nbr nbr.),
|
379
|
+
:apartment => %w(apartment apt apt.),
|
380
|
+
:building => %w(building bldg),
|
381
|
+
:department => %w(department dept),
|
382
|
+
:floor => %w(floor fl),
|
383
|
+
:room => %w(room rm),
|
384
|
+
:space => %w(space spc),
|
385
|
+
:stop => %w(stop stop),
|
386
|
+
:unit => %w(unit unit)
|
387
|
+
}
|
388
|
+
|
389
|
+
ORDINALS = {
|
390
|
+
:first => %w(first 1st),
|
391
|
+
:second => %w(second 2nd),
|
392
|
+
:third => %w(third 3rd),
|
393
|
+
:fourth => %w(fourth 4th forth),
|
394
|
+
:fifth => %w(fifth 5th),
|
395
|
+
:sixth => %w(sixth 6th),
|
396
|
+
:seventh => %w(seventh 7th),
|
397
|
+
:eighth => %w(eighth 8th),
|
398
|
+
:ninth => %w(ninth 9th),
|
399
|
+
:tenth => %w(tenth 10th),
|
400
|
+
:eleventh => %w(eleventh 11th),
|
401
|
+
:twelfth => %w(twelfth 12th),
|
402
|
+
:thirteenth => %w(thirteenth 13th),
|
403
|
+
:fourteenth => %w(fourteenth 14th),
|
404
|
+
:fifteenth => %w(fifteenth 15th),
|
405
|
+
:sixteenth => %w(sixteenth 16th),
|
406
|
+
:seventeenth => %w(seventeenth 17th),
|
407
|
+
:eighteenth => %w(eighteenth 18th),
|
408
|
+
:nineteenth => %w(nineteenth 19th)
|
177
409
|
}
|
178
410
|
|
411
|
+
# to_canonical_s format uses the short form
|
179
412
|
SUPPORTED_FORMS = [:long, :short]
|
180
413
|
end
|
181
414
|
end
|
data/lib/people_places_things.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: people_places_things
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 2
|
7
|
-
- 4
|
8
|
-
- 1
|
9
|
-
version: 2.4.1
|
4
|
+
prerelease:
|
5
|
+
version: 2.5.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Danny Burkes
|
@@ -14,24 +10,42 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
date: 2011-10-08 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.6.0
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - "="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.8.6
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
21
37
|
description: Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.
|
22
|
-
email:
|
38
|
+
email:
|
39
|
+
- dburkes@netable.com
|
23
40
|
executables: []
|
24
41
|
|
25
42
|
extensions: []
|
26
43
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
29
46
|
files:
|
30
|
-
- .gitignore
|
31
47
|
- README.textile
|
32
|
-
-
|
33
|
-
- lib/people_places_things.rb
|
34
|
-
- lib/people_places_things/VERSION
|
48
|
+
- LICENSE
|
35
49
|
- lib/people_places_things/ansi_counties.rb
|
36
50
|
- lib/people_places_things/data/data.yml
|
37
51
|
- lib/people_places_things/data/process_data.rb
|
@@ -41,52 +55,35 @@ files:
|
|
41
55
|
- lib/people_places_things/phone_number.rb
|
42
56
|
- lib/people_places_things/state.rb
|
43
57
|
- lib/people_places_things/street_address.rb
|
58
|
+
- lib/people_places_things/version.rb
|
44
59
|
- lib/people_places_things/zip_code.rb
|
45
|
-
- people_places_things.
|
46
|
-
- spec/ansi_counties_spec.rb
|
47
|
-
- spec/helper.rb
|
48
|
-
- spec/location_spec.rb
|
49
|
-
- spec/person_name_spec.rb
|
50
|
-
- spec/phone_number_spec.rb
|
51
|
-
- spec/state_spec.rb
|
52
|
-
- spec/street_address_spec.rb
|
53
|
-
- spec/zip_code_spec.rb
|
54
|
-
has_rdoc: true
|
60
|
+
- lib/people_places_things.rb
|
55
61
|
homepage: http://github.com/dburkes/people_places_things
|
56
62
|
licenses: []
|
57
63
|
|
58
64
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
65
|
+
rdoc_options: []
|
66
|
+
|
61
67
|
require_paths:
|
62
68
|
- lib
|
63
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
64
71
|
requirements:
|
65
72
|
- - ">="
|
66
73
|
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 0
|
69
74
|
version: "0"
|
70
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
71
77
|
requirements:
|
72
78
|
- - ">="
|
73
79
|
- !ruby/object:Gem::Version
|
74
|
-
segments:
|
75
|
-
- 0
|
76
80
|
version: "0"
|
77
81
|
requirements: []
|
78
82
|
|
79
83
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.8.7
|
81
85
|
signing_key:
|
82
86
|
specification_version: 3
|
83
87
|
summary: Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.
|
84
|
-
test_files:
|
85
|
-
|
86
|
-
- spec/helper.rb
|
87
|
-
- spec/location_spec.rb
|
88
|
-
- spec/person_name_spec.rb
|
89
|
-
- spec/phone_number_spec.rb
|
90
|
-
- spec/state_spec.rb
|
91
|
-
- spec/street_address_spec.rb
|
92
|
-
- spec/zip_code_spec.rb
|
88
|
+
test_files: []
|
89
|
+
|
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
begin; require 'rubygems'; rescue LoadError; end
|
2
|
-
|
3
|
-
require 'rake'
|
4
|
-
require 'rake/rdoctask'
|
5
|
-
require 'spec/rake/spectask'
|
6
|
-
|
7
|
-
desc "Run all specs"
|
8
|
-
Spec::Rake::SpecTask.new('specs') do |t|
|
9
|
-
t.libs << 'lib'
|
10
|
-
t.spec_files = FileList['spec/**/*.rb']
|
11
|
-
end
|
12
|
-
|
13
|
-
Dir['tasks/*.rake'].each{|f| import(f) }
|
14
|
-
|
15
|
-
task :default => [:specs]
|
16
|
-
|
17
|
-
begin
|
18
|
-
require 'jeweler'
|
19
|
-
require 'lib/people_places_things'
|
20
|
-
Jeweler::Tasks.new do |gemspec|
|
21
|
-
gemspec.name = "people_places_things"
|
22
|
-
gemspec.version = PeoplePlacesThings::VERSION
|
23
|
-
gemspec.summary = "Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc."
|
24
|
-
gemspec.email = "dburkes@netable.com"
|
25
|
-
gemspec.homepage = "http://github.com/dburkes/people_places_things"
|
26
|
-
gemspec.description = "Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc."
|
27
|
-
gemspec.authors = ["Danny Burkes"]
|
28
|
-
end
|
29
|
-
rescue LoadError
|
30
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
31
|
-
end
|
32
|
-
|
33
|
-
namespace :doc do
|
34
|
-
desc "Generate RDoc"
|
35
|
-
Rake::RDocTask.new('people_places_things') { |rdoc|
|
36
|
-
rdoc.rdoc_dir = 'doc'
|
37
|
-
rdoc.options << '--inline-source'
|
38
|
-
# rdoc.rdoc_files.include('README.md')
|
39
|
-
# rdoc.rdoc_files.include('lib/**/*')
|
40
|
-
# rdoc.rdoc_files.exclude('lib/ansi_counties/data/**/*')
|
41
|
-
}
|
42
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
2.3.0
|
@@ -1,70 +0,0 @@
|
|
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{people_places_things}
|
8
|
-
s.version = "2.4.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Danny Burkes"]
|
12
|
-
s.date = %q{2010-03-03}
|
13
|
-
s.description = %q{Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.}
|
14
|
-
s.email = %q{dburkes@netable.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.textile"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"README.textile",
|
21
|
-
"Rakefile",
|
22
|
-
"lib/people_places_things.rb",
|
23
|
-
"lib/people_places_things/VERSION",
|
24
|
-
"lib/people_places_things/ansi_counties.rb",
|
25
|
-
"lib/people_places_things/data/data.yml",
|
26
|
-
"lib/people_places_things/data/process_data.rb",
|
27
|
-
"lib/people_places_things/data/raw.txt",
|
28
|
-
"lib/people_places_things/location.rb",
|
29
|
-
"lib/people_places_things/person_name.rb",
|
30
|
-
"lib/people_places_things/phone_number.rb",
|
31
|
-
"lib/people_places_things/state.rb",
|
32
|
-
"lib/people_places_things/street_address.rb",
|
33
|
-
"lib/people_places_things/zip_code.rb",
|
34
|
-
"people_places_things.gemspec",
|
35
|
-
"spec/ansi_counties_spec.rb",
|
36
|
-
"spec/helper.rb",
|
37
|
-
"spec/location_spec.rb",
|
38
|
-
"spec/person_name_spec.rb",
|
39
|
-
"spec/phone_number_spec.rb",
|
40
|
-
"spec/state_spec.rb",
|
41
|
-
"spec/street_address_spec.rb",
|
42
|
-
"spec/zip_code_spec.rb"
|
43
|
-
]
|
44
|
-
s.homepage = %q{http://github.com/dburkes/people_places_things}
|
45
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
-
s.require_paths = ["lib"]
|
47
|
-
s.rubygems_version = %q{1.3.6}
|
48
|
-
s.summary = %q{Parsers and formatters for person names, street addresses, city/state/zip, phone numbers, etc.}
|
49
|
-
s.test_files = [
|
50
|
-
"spec/ansi_counties_spec.rb",
|
51
|
-
"spec/helper.rb",
|
52
|
-
"spec/location_spec.rb",
|
53
|
-
"spec/person_name_spec.rb",
|
54
|
-
"spec/phone_number_spec.rb",
|
55
|
-
"spec/state_spec.rb",
|
56
|
-
"spec/street_address_spec.rb",
|
57
|
-
"spec/zip_code_spec.rb"
|
58
|
-
]
|
59
|
-
|
60
|
-
if s.respond_to? :specification_version then
|
61
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
-
s.specification_version = 3
|
63
|
-
|
64
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
-
else
|
66
|
-
end
|
67
|
-
else
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
data/spec/ansi_counties_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe ANSICounties do
|
4
|
-
it "should find code for valid state and county" do
|
5
|
-
ANSICounties.code_for('ga', 'fulton').should == 13121
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should find code for valid state and county hash" do
|
9
|
-
ANSICounties.code_for(:state => 'ga', :county => 'fulton').should == 13121
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return nil for invalid state and county" do
|
13
|
-
ANSICounties.code_for(:state => 'ga', :county => 'fubar').should == nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should find code for alternate st. form" do
|
17
|
-
ANSICounties.code_for(:state => 'MO', :county => 'saint LOUIS').should == 29510
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should find data for valid code" do
|
21
|
-
ANSICounties.data_for(13121).should == { :state => 'GA', :county => 'FULTON' }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should return nil for invalid code" do
|
25
|
-
ANSICounties.data_for(1312111).should == nil
|
26
|
-
end
|
27
|
-
end
|
data/spec/helper.rb
DELETED
data/spec/location_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe Location do
|
4
|
-
it "should parse city" do
|
5
|
-
test_location("san francisco", "san francisco", nil, nil)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should parse city state abbreviation" do
|
9
|
-
test_location("san francisco ca", "san francisco", "CA", nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should parse city state full" do
|
13
|
-
test_location("san francisco california", "san francisco", "CA", nil)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should parse city comma state" do
|
17
|
-
test_location("san francisco, ca", "san francisco", "CA", nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should parse city state zip" do
|
21
|
-
test_location("san francisco ca 94114-1212", "san francisco", "CA", '94114-1212')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should parse city comma state zip" do
|
25
|
-
test_location("san francisco, ca 94114-1212", "san francisco", "CA", '94114-1212')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should parse city zip" do
|
29
|
-
test_location("san francisco 94114-1212", "san francisco", nil, '94114-1212')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should parse state zip" do
|
33
|
-
test_location("ca 94114-1212", nil, "CA", '94114-1212')
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should parse state" do
|
37
|
-
test_location("california", nil, "CA", nil)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should parse zip" do
|
41
|
-
test_location("94114-1212", nil, nil, '94114-1212')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should save raw" do
|
45
|
-
Location.new('san francisco, ca').raw.should == 'san francisco, ca'
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def test_location(str, city, state, zip)
|
51
|
-
l = Location.new(str)
|
52
|
-
l.city.should == city if l.city
|
53
|
-
l.state.to_s(:abbr).should == state.upcase if l.state
|
54
|
-
l.zip.to_s.should == zip if l.zip
|
55
|
-
end
|
56
|
-
end
|
data/spec/person_name_spec.rb
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe PersonName do
|
4
|
-
it "should parse first_middle_last" do
|
5
|
-
name = PersonName.new "george quincy drake peabody", :first_middle_last
|
6
|
-
name.first.should == 'george'
|
7
|
-
name.middle.should == 'quincy drake'
|
8
|
-
name.last.should == 'peabody'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should parse last_first_middle" do
|
12
|
-
name = PersonName.new "peabody george quincy drake", :last_first_middle
|
13
|
-
name.first.should == 'george'
|
14
|
-
name.middle.should == 'quincy drake'
|
15
|
-
name.last.should == 'peabody'
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should parse last only in first_middle_last format" do
|
19
|
-
name = PersonName.new "peabody", :first_middle_last
|
20
|
-
name.first.should == nil
|
21
|
-
name.middle.should == nil
|
22
|
-
name.last.should == 'peabody'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should parse last only in last_first_middle format" do
|
26
|
-
name = PersonName.new "peabody", :last_first_middle
|
27
|
-
name.first.should == nil
|
28
|
-
name.middle.should == nil
|
29
|
-
name.last.should == 'peabody'
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should parse first middle last suffix" do
|
33
|
-
name = PersonName.new "george f. peabody jr"
|
34
|
-
name.first.should == 'george'
|
35
|
-
name.middle.should == 'f.'
|
36
|
-
name.last.should == 'peabody'
|
37
|
-
name.suffix.should == 'jr'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should not parse middle initial as suffix" do
|
41
|
-
name = PersonName.new "brown, james v"
|
42
|
-
name.first.should == 'james'
|
43
|
-
name.middle.should == 'v'
|
44
|
-
name.last.should == 'brown'
|
45
|
-
name.suffix.should == nil
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should parse last suffix first middle" do
|
49
|
-
name = PersonName.new "peabody jr george f.", :last_first_middle
|
50
|
-
name.first.should == 'george'
|
51
|
-
name.middle.should == 'f.'
|
52
|
-
name.last.should == 'peabody'
|
53
|
-
name.suffix.should == 'jr'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should parse last first middle suffix" do
|
57
|
-
name = PersonName.new "peabody, george f., jr.", :last_first_middle
|
58
|
-
name.first.should == 'george'
|
59
|
-
name.middle.should == 'f.'
|
60
|
-
name.last.should == 'peabody'
|
61
|
-
name.suffix.should == 'jr'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should default to first_middle_last" do
|
65
|
-
name = PersonName.new "george quincy drake peabody"
|
66
|
-
name.first.should == 'george'
|
67
|
-
name.middle.should == 'quincy drake'
|
68
|
-
name.last.should == 'peabody'
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should ignore spaces and commas" do
|
72
|
-
name = PersonName.new " peabody,george quincy drake ", :last_first_middle
|
73
|
-
name.first.should == 'george'
|
74
|
-
name.middle.should == 'quincy drake'
|
75
|
-
name.last.should == 'peabody'
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should strip periods from initials" do
|
79
|
-
name = PersonName.new "george f. peabody", :first_middle_last
|
80
|
-
name.first.should == 'george'
|
81
|
-
name.middle.should == 'f.'
|
82
|
-
name.middle_i == 'f'
|
83
|
-
name.last.should == 'peabody'
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should format for :first" do
|
87
|
-
name = PersonName.new "george quincy peabody"
|
88
|
-
name.to_s(:first).should == 'george'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should format for :middle" do
|
92
|
-
name = PersonName.new "george quincy peabody"
|
93
|
-
name.to_s(:middle).should == 'quincy'
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should format for :last" do
|
97
|
-
name = PersonName.new "george quincy peabody"
|
98
|
-
name.to_s(:last).should == 'peabody'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should format for :full" do
|
102
|
-
name = PersonName.new "george quincy peabody"
|
103
|
-
name.to_s(:full).should == 'george quincy peabody'
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should format for :full_reverse" do
|
107
|
-
name = PersonName.new "george quincy peabody jr."
|
108
|
-
name.to_s(:full_reverse).should == 'peabody george quincy jr'
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should format for :first_space_last" do
|
112
|
-
name = PersonName.new "george quincy peabody"
|
113
|
-
name.to_s(:first_space_last).should == 'george peabody'
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should format for :last_space_first" do
|
117
|
-
name = PersonName.new "george quincy peabody"
|
118
|
-
name.to_s(:last_space_first).should == 'peabody george'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should format for :last_comma_first" do
|
122
|
-
name = PersonName.new "george quincy peabody"
|
123
|
-
name.to_s(:last_comma_first).should == 'peabody,george'
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should format for :last_comma_space_first" do
|
127
|
-
name = PersonName.new "george quincy peabody"
|
128
|
-
name.to_s(:last_comma_space_first).should == 'peabody, george'
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should handle missing parts when formatting" do
|
132
|
-
PersonName.new('peabody').to_s(:last_comma_space_first).should == 'peabody'
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should respond to individual accessors" do
|
136
|
-
name = PersonName.new "george quincy peabody"
|
137
|
-
name.first.should == 'george'
|
138
|
-
name.first_i.should == 'g'
|
139
|
-
name.middle.should == 'quincy'
|
140
|
-
name.middle_i.should == 'q'
|
141
|
-
name.last.should == 'peabody'
|
142
|
-
name.last_i.should == 'p'
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should recognize exact equality" do
|
146
|
-
PersonName.new("george quincy peabody").should be_eql(PersonName.new("george quincy peabody"))
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should ignore case for equality" do
|
150
|
-
PersonName.new("george quincy peabody").should be_eql(PersonName.new("george quincy PEABODY"))
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should recognize subset equality" do
|
154
|
-
PersonName.new("george quincy peabody").should be_eql(PersonName.new("george peabody"))
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should parse mc donald for first_middle_last" do
|
158
|
-
name = PersonName.new "george quincy drake mc donald", :first_middle_last
|
159
|
-
name.first.should == 'george'
|
160
|
-
name.middle.should == 'quincy drake'
|
161
|
-
name.last.should == 'mcdonald'
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should parse mc donald for last_first_middle" do
|
165
|
-
name = PersonName.new "mc donald george quincy drake", :last_first_middle
|
166
|
-
name.first.should == 'george'
|
167
|
-
name.middle.should == 'quincy drake'
|
168
|
-
name.last.should == 'mcdonald'
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should normalize suffixes" do
|
172
|
-
name = PersonName.new "george quincy peabody jr"
|
173
|
-
name2 = PersonName.new "peabody jr., george quincy", :last_first_middle
|
174
|
-
name.should be_eql(name2)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should support auto detect formatting for first_middle_last" do
|
178
|
-
name = PersonName.new "george f. peabody jr"
|
179
|
-
name.first.should == 'george'
|
180
|
-
name.middle.should == 'f.'
|
181
|
-
name.last.should == 'peabody'
|
182
|
-
name.suffix.should == 'jr'
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should support auto detect formatting for last_first_middle" do
|
186
|
-
name = PersonName.new "peabody, george quincy drake"
|
187
|
-
name.first.should == 'george'
|
188
|
-
name.middle.should == 'quincy drake'
|
189
|
-
name.last.should == 'peabody'
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should save raw" do
|
193
|
-
PersonName.new("ronald mcdonald").raw.should == 'ronald mcdonald'
|
194
|
-
end
|
195
|
-
end
|
data/spec/phone_number_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe PhoneNumber do
|
4
|
-
it "should parse ten digits" do
|
5
|
-
phone = PhoneNumber.new '4045551212'
|
6
|
-
phone.area_code.should == '404'
|
7
|
-
phone.number.should == '5551212'
|
8
|
-
phone.exchange.should == '555'
|
9
|
-
phone.suffix.should == '1212'
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should parse eleven digits" do
|
13
|
-
phone = PhoneNumber.new '14045551212'
|
14
|
-
phone.area_code.should == '404'
|
15
|
-
phone.number.should == '5551212'
|
16
|
-
phone.exchange.should == '555'
|
17
|
-
phone.suffix.should == '1212'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should ignore certain characters" do
|
21
|
-
phone = PhoneNumber.new '1 (404) 555-1212'
|
22
|
-
phone.area_code.should == '404'
|
23
|
-
phone.number.should == '5551212'
|
24
|
-
phone.exchange.should == '555'
|
25
|
-
phone.suffix.should == '1212'
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should support international format, at least for US numbers, for now" do
|
29
|
-
phone = PhoneNumber.new '+1 404 555-1212'
|
30
|
-
phone.area_code.should == '404'
|
31
|
-
phone.number.should == '5551212'
|
32
|
-
phone.exchange.should == '555'
|
33
|
-
phone.suffix.should == '1212'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should throw exception on unsupported parse format" do
|
37
|
-
lambda { PhoneNumber.new('40455512') }.should raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should format :full_digits" do
|
41
|
-
PhoneNumber.new('14045551212').to_s(:full_digits).should == '14045551212'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should format :local_digits" do
|
45
|
-
PhoneNumber.new('14045551212').to_s(:local_digits).should == '5551212'
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should format :full_formatted" do
|
49
|
-
PhoneNumber.new('14045551212').to_s(:full_formatted).should == '1 (404) 555-1212'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should format :local_formatted" do
|
53
|
-
PhoneNumber.new('14045551212').to_s(:local_formatted).should == '555-1212'
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should throw exception on unsupported to_sformat" do
|
57
|
-
lambda { PhoneNumber.new('14045551212').to_s(:bogus) }.should raise_error
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should save raw" do
|
61
|
-
PhoneNumber.new('14045551212').raw.should == '14045551212'
|
62
|
-
end
|
63
|
-
end
|
data/spec/state_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe State do
|
4
|
-
it "should parse abbreviation" do
|
5
|
-
state = State.new 'ga'
|
6
|
-
state.sym.should == :ga
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should parse full" do
|
10
|
-
state = State.new 'georgia'
|
11
|
-
state.sym.should == :ga
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should throw exception on unsupported state" do
|
15
|
-
lambda { State.new('foo') }.should raise_error
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should format :abbr" do
|
19
|
-
State.new('ga').to_s(:abbr).should == 'GA'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should format :full" do
|
23
|
-
State.new('ga').to_s(:full).should == 'Georgia'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should throw exception on unsupported to_s format" do
|
27
|
-
lambda { State.new('ga').to_s(:bogus) }.should raise_error
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should save raw" do
|
31
|
-
State.new('georgia').raw.should == 'georgia'
|
32
|
-
end
|
33
|
-
end
|
data/spec/street_address_spec.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe StreetAddress do
|
4
|
-
it "should parse number street" do
|
5
|
-
addr = StreetAddress.new "123 Main Street"
|
6
|
-
addr.number.should == '123'
|
7
|
-
addr.name.should == 'Main'
|
8
|
-
addr.suffix.should == :street
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should parse number with letter" do
|
12
|
-
addr = StreetAddress.new "204-B Main Street"
|
13
|
-
addr.number.should == '204-B'
|
14
|
-
addr.name.should == 'Main'
|
15
|
-
addr.suffix.should == :street
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should parse pre direction" do
|
19
|
-
addr = StreetAddress.new "123 E Main Street"
|
20
|
-
addr.number.should == '123'
|
21
|
-
addr.pre_direction.should == :east
|
22
|
-
addr.name.should == 'Main'
|
23
|
-
addr.suffix.should == :street
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should parse post direction" do
|
27
|
-
addr = StreetAddress.new "123 Main Street NE"
|
28
|
-
addr.number.should == '123'
|
29
|
-
addr.name.should == 'Main'
|
30
|
-
addr.suffix.should == :street
|
31
|
-
addr.post_direction.should == :northeast
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should parse pre and post direction" do
|
35
|
-
addr = StreetAddress.new "123 E Main Street North"
|
36
|
-
addr.number.should == '123'
|
37
|
-
addr.pre_direction.should == :east
|
38
|
-
addr.name.should == 'Main'
|
39
|
-
addr.suffix.should == :street
|
40
|
-
addr.post_direction.should == :north
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should parse street names that look like directions" do
|
44
|
-
addr = StreetAddress.new "123 E E St"
|
45
|
-
addr.number.should == '123'
|
46
|
-
addr.pre_direction.should == :east
|
47
|
-
addr.name.should == 'E'
|
48
|
-
addr.suffix.should == :street
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should parse street names that look like directions, with post directions" do
|
52
|
-
addr = StreetAddress.new "123 E E St NE"
|
53
|
-
addr.number.should == '123'
|
54
|
-
addr.pre_direction.should == :east
|
55
|
-
addr.name.should == 'E'
|
56
|
-
addr.suffix.should == :street
|
57
|
-
addr.post_direction.should == :northeast
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should parse abbreviations" do
|
61
|
-
addr = StreetAddress.new "123 e. 1st ave"
|
62
|
-
addr.number.should == '123'
|
63
|
-
addr.pre_direction.should == :east
|
64
|
-
addr.name.should == '1st'
|
65
|
-
addr.suffix.should == :avenue
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should parse suites" do
|
69
|
-
addr = StreetAddress.new "123 E E St NE Ste 23"
|
70
|
-
addr.number.should == '123'
|
71
|
-
addr.pre_direction.should == :east
|
72
|
-
addr.name.should == 'E'
|
73
|
-
addr.suffix.should == :street
|
74
|
-
addr.post_direction.should == :northeast
|
75
|
-
addr.unit_type.should == :suite
|
76
|
-
addr.unit.should == '23'
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should parse apartments" do
|
80
|
-
addr = StreetAddress.new "123 E E St NE Apartment 4"
|
81
|
-
addr.number.should == '123'
|
82
|
-
addr.pre_direction.should == :east
|
83
|
-
addr.name.should == 'E'
|
84
|
-
addr.suffix.should == :street
|
85
|
-
addr.post_direction.should == :northeast
|
86
|
-
addr.unit_type.should == :apartment
|
87
|
-
addr.unit.should == '4'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should parse numbers" do
|
91
|
-
addr = StreetAddress.new '123 E E St NE # 5'
|
92
|
-
addr.number.should == '123'
|
93
|
-
addr.pre_direction.should == :east
|
94
|
-
addr.name.should == 'E'
|
95
|
-
addr.suffix.should == :street
|
96
|
-
addr.post_direction.should == :northeast
|
97
|
-
addr.unit_type.should == :number
|
98
|
-
addr.unit.should == '5'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should parse no number" do
|
102
|
-
addr = StreetAddress.new "Westside Highway"
|
103
|
-
addr.number.should == nil
|
104
|
-
addr.name.should == 'Westside'
|
105
|
-
addr.suffix.should == :highway
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should parse directional street with suffix" do
|
109
|
-
addr = StreetAddress.new "12 north avenue"
|
110
|
-
addr.number.should == '12'
|
111
|
-
addr.name.should == 'north'
|
112
|
-
addr.suffix.should == :avenue
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should parse directional street without suffix" do
|
116
|
-
addr = StreetAddress.new "12 north"
|
117
|
-
addr.number.should == '12'
|
118
|
-
addr.name.should == 'north'
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should parse directional street with postdir" do
|
122
|
-
addr = StreetAddress.new "12 north w"
|
123
|
-
addr.number.should == '12'
|
124
|
-
addr.name.should == 'north'
|
125
|
-
addr.post_direction.should == :west
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should parse directional street with postdir and unit" do
|
129
|
-
addr = StreetAddress.new "12 n sw apt. 2"
|
130
|
-
addr.number.should == '12'
|
131
|
-
addr.name.should == 'n'
|
132
|
-
addr.post_direction.should == :southwest
|
133
|
-
addr.unit_type.should == :apartment
|
134
|
-
addr.unit.should == '2'
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should handle commas" do
|
138
|
-
addr = StreetAddress.new "123 E E St NE, suite 23"
|
139
|
-
addr.number.should == '123'
|
140
|
-
addr.pre_direction.should == :east
|
141
|
-
addr.name.should == 'E'
|
142
|
-
addr.suffix.should == :street
|
143
|
-
addr.post_direction.should == :northeast
|
144
|
-
addr.unit_type.should == :suite
|
145
|
-
addr.unit.should == '23'
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should support long form" do
|
149
|
-
StreetAddress.string_for(:northwest, :long).should == 'northwest'
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should support short form" do
|
153
|
-
StreetAddress.string_for(:road, :short).should == 'rd'
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should support short form when none exists" do
|
157
|
-
StreetAddress.string_for(:oaks, :short).should == StreetAddress.string_for(:oaks, :long)
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should save raw" do
|
161
|
-
StreetAddress.new('123 Main st.').raw.should == '123 Main st.'
|
162
|
-
end
|
163
|
-
end
|
data/spec/zip_code_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec/helper'
|
2
|
-
|
3
|
-
describe ZipCode do
|
4
|
-
it "should parse base" do
|
5
|
-
zip = ZipCode.new '30306'
|
6
|
-
zip.base.should == '30306'
|
7
|
-
zip.plus_four.should == nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should parse plus four" do
|
11
|
-
zip = ZipCode.new '30306-3522'
|
12
|
-
zip.base.should == '30306'
|
13
|
-
zip.plus_four.should == '3522'
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should throw exception on unsupported parse format" do
|
17
|
-
lambda { ZipCode.new('303065344') }.should raise_error
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should convert to string" do
|
21
|
-
ZipCode.new('30306-3522').to_s.should == '30306-3522'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should throw exception on unsupported to_s format" do
|
25
|
-
lambda { ZipCode.new('30306-3522').to_s(:bogus) }.should raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should save raw format" do
|
29
|
-
ZipCode.new('30306-3522').raw.should == '30306-3522'
|
30
|
-
end
|
31
|
-
end
|