people 0.2.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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +62 -0
- data/VERSION.yml +4 -0
- data/lib/people.rb +499 -0
- data/people.gemspec +50 -0
- data/test/people_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +78 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Matthew Ericson
|
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.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
|
7
|
+
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "people"
|
10
|
+
gem.summary = %Q{Matts Name Parser}
|
11
|
+
gem.email = "mericson@ericson.net"
|
12
|
+
gem.homepage = "http://github.com/mericson/people"
|
13
|
+
gem.authors = ["Matthew Ericson"]
|
14
|
+
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
|
20
|
+
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/*_test.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/*_test.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
if File.exist?('VERSION.yml')
|
51
|
+
config = YAML.load(File.read('VERSION.yml'))
|
52
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
53
|
+
else
|
54
|
+
version = ""
|
55
|
+
end
|
56
|
+
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "people #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
62
|
+
|
data/VERSION.yml
ADDED
data/lib/people.rb
ADDED
@@ -0,0 +1,499 @@
|
|
1
|
+
module People
|
2
|
+
|
3
|
+
# Class to parse names into their components like first, middle, last, etc.
|
4
|
+
class NameParser
|
5
|
+
|
6
|
+
attr_reader :seen, :parsed
|
7
|
+
|
8
|
+
# Creates a name parsing object
|
9
|
+
def initialize( opts={} )
|
10
|
+
|
11
|
+
@name_chars = "A-Za-z0-9\\-\\'"
|
12
|
+
@nc = @name_chars
|
13
|
+
|
14
|
+
@opts = {
|
15
|
+
:strip_mr => true,
|
16
|
+
:strip_mrs => false,
|
17
|
+
:case_mode => 'proper',
|
18
|
+
:couples => false
|
19
|
+
}.merge! opts
|
20
|
+
|
21
|
+
## constants
|
22
|
+
|
23
|
+
@titles = [ 'Mr\.? and Mrs\.? ',
|
24
|
+
'Mrs\.? ',
|
25
|
+
'M/s\.? ',
|
26
|
+
'Ms\.? ',
|
27
|
+
'Miss\.? ',
|
28
|
+
'Mme\.? ',
|
29
|
+
'Mr\.? ',
|
30
|
+
'Messrs ',
|
31
|
+
'Mister ',
|
32
|
+
'Mast(\.|er)? ',
|
33
|
+
'Ms?gr\.? ',
|
34
|
+
'Sir ',
|
35
|
+
'Lord ',
|
36
|
+
'Lady ',
|
37
|
+
'Madam(e)? ',
|
38
|
+
'Dame ',
|
39
|
+
|
40
|
+
# Medical
|
41
|
+
'Dr\.? ',
|
42
|
+
'Doctor ',
|
43
|
+
'Sister ',
|
44
|
+
'Matron ',
|
45
|
+
|
46
|
+
# Legal
|
47
|
+
'Judge ',
|
48
|
+
'Justice ',
|
49
|
+
|
50
|
+
# Police
|
51
|
+
'Det\.? ',
|
52
|
+
'Insp\.? ',
|
53
|
+
|
54
|
+
# Military
|
55
|
+
'Brig(adier)? ',
|
56
|
+
'Capt(\.|ain)? ',
|
57
|
+
'Commander ',
|
58
|
+
'Commodore ',
|
59
|
+
'Cdr\.? ',
|
60
|
+
'Colonel ',
|
61
|
+
'Gen(\.|eral)? ',
|
62
|
+
'Field Marshall ',
|
63
|
+
'Fl\.? Off\.? ',
|
64
|
+
'Flight Officer ',
|
65
|
+
'Flt Lt ',
|
66
|
+
'Flight Lieutenant ',
|
67
|
+
'Pte\. ',
|
68
|
+
'Private ',
|
69
|
+
'Sgt\.? ',
|
70
|
+
'Sargent ',
|
71
|
+
'Air Commander ',
|
72
|
+
'Air Commodore ',
|
73
|
+
'Air Marshall ',
|
74
|
+
'Lieutenant Colonel ',
|
75
|
+
'Lt\.? Col\.? ',
|
76
|
+
'Lt\.? Gen\.? ',
|
77
|
+
'Lt\.? Cdr\.? ',
|
78
|
+
'Lieutenant ',
|
79
|
+
'(Lt|Leut|Lieut)\.? ',
|
80
|
+
'Major General ',
|
81
|
+
'Maj\.? Gen\.?',
|
82
|
+
'Major ',
|
83
|
+
'Maj\.? ',
|
84
|
+
|
85
|
+
# Religious
|
86
|
+
'Rabbi ',
|
87
|
+
'Brother ',
|
88
|
+
'Father ',
|
89
|
+
'Chaplain ',
|
90
|
+
'Pastor ',
|
91
|
+
'Bishop ',
|
92
|
+
'Mother Superior ',
|
93
|
+
'Mother ',
|
94
|
+
'Most Rever[e|a]nd ',
|
95
|
+
'Very Rever[e|a]nd ',
|
96
|
+
'Mt\.? Revd\.? ',
|
97
|
+
'V\.? Revd?\.? ',
|
98
|
+
'Rever[e|a]nd ',
|
99
|
+
'Revd?\.? ',
|
100
|
+
|
101
|
+
# Other
|
102
|
+
'Prof(\.|essor)? ',
|
103
|
+
'Ald(\.|erman)? '
|
104
|
+
];
|
105
|
+
|
106
|
+
|
107
|
+
@suffixes = [
|
108
|
+
'Jn?r\.?,? Esq\.?',
|
109
|
+
'Sn?r\.?,? Esq\.?',
|
110
|
+
'I{1,3},? Esq\.?',
|
111
|
+
|
112
|
+
'Jn?r\.?,? M\.?D\.?',
|
113
|
+
'Sn?r\.?,? M\.?D\.?',
|
114
|
+
'I{1,3},? M\.?D\.?',
|
115
|
+
|
116
|
+
'Sn?r\.?', # Senior
|
117
|
+
'Jn?r\.?', # Junior
|
118
|
+
|
119
|
+
'Esq(\.|uire)?',
|
120
|
+
'Esquire.',
|
121
|
+
'Attorney at Law.',
|
122
|
+
'Attorney-at-Law.',
|
123
|
+
|
124
|
+
'Ph\.?d\.?',
|
125
|
+
'C\.?P\.?A\.?',
|
126
|
+
|
127
|
+
'XI{1,3}', # 11th, 12th, 13th
|
128
|
+
'X', # 10th
|
129
|
+
'IV', # 4th
|
130
|
+
'VI{1,3}', # 6th, 7th, 8th
|
131
|
+
'V', # 5th
|
132
|
+
'IX', # 9th
|
133
|
+
'I{1,3}\.?', # 1st, 2nd, 3rd
|
134
|
+
'M\.?D\.?', # M.D.
|
135
|
+
'D.?M\.?D\.?' # M.D.
|
136
|
+
];
|
137
|
+
|
138
|
+
@last_name_p = "((;.+)|(((Mc|Mac|Des|Dell[ae]|Del|De La|De Los|Da|Di|Du|La|Le|Lo|St\.|Den|Von|Van|Von Der|Van De[nr]) )?([#{@nc}]+)))";
|
139
|
+
@mult_name_p = "((;.+)|(((Mc|Mac|Des|Dell[ae]|Del|De La|De Los|Da|Di|Du|La|Le|Lo|St\.|Den|Von|Van|Von Der|Van De[nr]) )?([#{@nc} ]+)))";
|
140
|
+
|
141
|
+
@seen = 0
|
142
|
+
@parsed = 0;
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
def parse( name )
|
147
|
+
|
148
|
+
@seen += 1
|
149
|
+
|
150
|
+
clean = ''
|
151
|
+
out = Hash.new( "" )
|
152
|
+
|
153
|
+
out[:orig] = name.dup
|
154
|
+
|
155
|
+
name = name.dup
|
156
|
+
|
157
|
+
name = clean( name )
|
158
|
+
|
159
|
+
# strip trailing suffices
|
160
|
+
@suffixes.each do |sfx|
|
161
|
+
sfx_p = Regexp.new( "(.+), (#{sfx})$", true )
|
162
|
+
##puts sfx_p
|
163
|
+
name.gsub!( sfx_p, "\\1 \\2" )
|
164
|
+
end
|
165
|
+
|
166
|
+
name.gsub!( /Mr\.? \& Mrs\.?/i, "Mr. and Mrs." )
|
167
|
+
|
168
|
+
# Flip last and first if contain comma
|
169
|
+
name.gsub!( /;/, "" )
|
170
|
+
name.gsub!( /(.+),(.+)/, "\\2 ;\\1" )
|
171
|
+
|
172
|
+
|
173
|
+
name.gsub!( /,/, "" )
|
174
|
+
name.strip!
|
175
|
+
|
176
|
+
if @opts[:couples]
|
177
|
+
name.gsub!( / +and +/i, " \& " )
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
if @opts[:couples] && name.match( /\&/ )
|
183
|
+
|
184
|
+
names = name.split( / *& */ )
|
185
|
+
a = names[0]
|
186
|
+
b = names[1]
|
187
|
+
|
188
|
+
out[:title2] = get_title( b );
|
189
|
+
out[:suffix2] = get_suffix( b );
|
190
|
+
|
191
|
+
b.strip!
|
192
|
+
|
193
|
+
parts = get_name_parts( b )
|
194
|
+
|
195
|
+
out[:parsed2] = parts[0]
|
196
|
+
out[:parse_type2] = parts[1]
|
197
|
+
out[:first2] = parts[2]
|
198
|
+
out[:middle2] = parts[3]
|
199
|
+
out[:last] = parts[4]
|
200
|
+
|
201
|
+
out[:title] = get_title( a );
|
202
|
+
out[:suffix] = get_suffix( a );
|
203
|
+
|
204
|
+
a.strip!
|
205
|
+
a += " "
|
206
|
+
|
207
|
+
parts = get_name_parts( a, true )
|
208
|
+
|
209
|
+
out[:parsed] = parts[0]
|
210
|
+
out[:parse_type] = parts[1]
|
211
|
+
out[:first] = parts[2]
|
212
|
+
out[:middle] = parts[3]
|
213
|
+
|
214
|
+
if out[:parsed] && out[:parsed2]
|
215
|
+
out[:multiple] = true
|
216
|
+
else
|
217
|
+
out = Hash.new( "" )
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
else
|
222
|
+
|
223
|
+
out[:title] = get_title( name );
|
224
|
+
out[:suffix] = get_suffix( name );
|
225
|
+
|
226
|
+
parts = get_name_parts( name )
|
227
|
+
|
228
|
+
out[:parsed] = parts[0]
|
229
|
+
out[:parse_type] = parts[1]
|
230
|
+
out[:first] = parts[2]
|
231
|
+
out[:middle] = parts[3]
|
232
|
+
out[:last] = parts[4]
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
if @opts[:case_mode] == 'proper'
|
238
|
+
[ :title, :first, :middle, :last, :suffix, :clean, :first2, :middle2, :title2, :suffix2 ].each do |part|
|
239
|
+
next if part == :suffix && out[part].match( /^[iv]+$/i );
|
240
|
+
out[part] = proper( out[part] )
|
241
|
+
end
|
242
|
+
|
243
|
+
elsif @opts[:case_mode] == 'upper'
|
244
|
+
[ :title, :first, :middle, :last, :suffix, :clean, :first2, :middle2, :title2, :suffix2 ].each do |part|
|
245
|
+
out[part].upcase!
|
246
|
+
end
|
247
|
+
|
248
|
+
else
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
if out[:parsed]
|
253
|
+
@parsed += 1
|
254
|
+
end
|
255
|
+
|
256
|
+
out[:clean] = name
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
return {
|
263
|
+
:title => "",
|
264
|
+
:first => "",
|
265
|
+
:middle => "",
|
266
|
+
:last => "",
|
267
|
+
:suffix => "",
|
268
|
+
|
269
|
+
:title2 => "",
|
270
|
+
:first2 => "",
|
271
|
+
:middle2 => "",
|
272
|
+
:suffix2 => "",
|
273
|
+
|
274
|
+
:clean => "",
|
275
|
+
|
276
|
+
:parsed => false,
|
277
|
+
:parse_type => "",
|
278
|
+
|
279
|
+
:parsed => false,
|
280
|
+
:parse_type => "",
|
281
|
+
|
282
|
+
:parsed2 => false,
|
283
|
+
:parse_type2 => "",
|
284
|
+
|
285
|
+
:multiple => false
|
286
|
+
}.merge( out )
|
287
|
+
|
288
|
+
end
|
289
|
+
|
290
|
+
|
291
|
+
def clean( s )
|
292
|
+
|
293
|
+
# remove illegal characters
|
294
|
+
s.gsub!( /[^A-Za-z0-9\-\'\.&\/ \,]/, "" )
|
295
|
+
# remove repeating spaces
|
296
|
+
s.gsub!( / +/, " " )
|
297
|
+
s.gsub!( /\s+/, " " )
|
298
|
+
s.strip!
|
299
|
+
s
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
def get_title( name )
|
304
|
+
|
305
|
+
@titles.each do |title|
|
306
|
+
title_p = Regexp.new( "^(#{title})(.+)", true )
|
307
|
+
if m = name.match( title_p )
|
308
|
+
|
309
|
+
title = m[1]
|
310
|
+
name.replace( m[-1].strip )
|
311
|
+
return title
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
return ""
|
317
|
+
end
|
318
|
+
|
319
|
+
def get_suffix( name )
|
320
|
+
|
321
|
+
@suffixes.each do |sfx|
|
322
|
+
sfx_p = Regexp.new( "(.+) (#{sfx})$", true )
|
323
|
+
if name.match( sfx_p )
|
324
|
+
name.replace $1.strip
|
325
|
+
suffix = $2
|
326
|
+
return $2
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
return ""
|
332
|
+
end
|
333
|
+
|
334
|
+
def get_name_parts( name, no_last_name = false )
|
335
|
+
|
336
|
+
first = ""
|
337
|
+
middle = ""
|
338
|
+
last = ""
|
339
|
+
|
340
|
+
if no_last_name
|
341
|
+
last_name_p = ''
|
342
|
+
mult_name_p = ''
|
343
|
+
else
|
344
|
+
last_name_p = @last_name_p
|
345
|
+
mult_name_p = @mult_name_p
|
346
|
+
end
|
347
|
+
|
348
|
+
parsed = false
|
349
|
+
|
350
|
+
# M ERICSON
|
351
|
+
if name.match( /^([A-Za-z])\.? (#{last_name_p})$/i )
|
352
|
+
first = $1;
|
353
|
+
middle = '';
|
354
|
+
last = $2;
|
355
|
+
parsed = true
|
356
|
+
parse_type = 1;
|
357
|
+
|
358
|
+
# M E ERICSON
|
359
|
+
elsif name.match( /^([A-Za-z])\.? ([A-Za-z])\.? (#{last_name_p})$/i )
|
360
|
+
first = $1;
|
361
|
+
middle = $2;
|
362
|
+
last = $3;
|
363
|
+
parsed = true
|
364
|
+
parse_type = 2;
|
365
|
+
|
366
|
+
# M.E. ERICSON
|
367
|
+
elsif name.match( /^([A-Za-z])\.([A-Za-z])\. (#{last_name_p})$/i )
|
368
|
+
first = $1;
|
369
|
+
middle = $2;
|
370
|
+
last = $3;
|
371
|
+
parsed = true
|
372
|
+
parse_type = 3;
|
373
|
+
|
374
|
+
# M E E ERICSON
|
375
|
+
elsif name.match( /^([A-Za-z])\.? ([A-Za-z])\.? ([A-Za-z])\.? (#{last_name_p})$/i )
|
376
|
+
first = $1;
|
377
|
+
middle = $2 + ' ' + $3;
|
378
|
+
last = $4;
|
379
|
+
parsed = true
|
380
|
+
parse_type = 4;
|
381
|
+
|
382
|
+
# M EDWARD ERICSON
|
383
|
+
elsif name.match( /^([A-Za-z])\.? ([#{@nc}]+) (#{last_name_p})$/i )
|
384
|
+
first = $1;
|
385
|
+
middle = $2;
|
386
|
+
last = $3;
|
387
|
+
parsed = true
|
388
|
+
parse_type = 5;
|
389
|
+
|
390
|
+
# MATTHEW E ERICSON
|
391
|
+
elsif name.match( /^([#{@nc}]+) ([A-Za-z])\.? (#{last_name_p})$/i )
|
392
|
+
first = $1;
|
393
|
+
middle = $2;
|
394
|
+
last = $3;
|
395
|
+
parsed = true
|
396
|
+
parse_type = 6;
|
397
|
+
|
398
|
+
# MATTHEW E E ERICSON
|
399
|
+
elsif name.match( /^([#{@nc}]+) ([A-Za-z])\.? ([A-Za-z])\.? (#{last_name_p})$/i )
|
400
|
+
first = $1;
|
401
|
+
middle = $2 + ' ' + $3;
|
402
|
+
last = $4;
|
403
|
+
parsed = true
|
404
|
+
parse_type = 7;
|
405
|
+
|
406
|
+
# MATTHEW E.E. ERICSON
|
407
|
+
elsif name.match( /^([#{@nc}]+) ([A-Za-z]\.[A-Za-z]\.) (#{last_name_p})$/i )
|
408
|
+
first = $1;
|
409
|
+
middle = $2;
|
410
|
+
last = $3;
|
411
|
+
parsed = true
|
412
|
+
parse_type = 8;
|
413
|
+
|
414
|
+
# MATTHEW ERICSON
|
415
|
+
elsif name.match( /^([#{@nc}]+) (#{last_name_p})$/i )
|
416
|
+
first = $1;
|
417
|
+
middle = '';
|
418
|
+
last = $2;
|
419
|
+
parsed = true
|
420
|
+
parse_type = 9;
|
421
|
+
|
422
|
+
# MATTHEW EDWARD ERICSON
|
423
|
+
elsif name.match( /^([#{@nc}]+) ([#{@nc}]+) (#{last_name_p})$/i )
|
424
|
+
first = $1;
|
425
|
+
middle = $2;
|
426
|
+
last = $3;
|
427
|
+
parsed = true
|
428
|
+
parse_type = 10;
|
429
|
+
|
430
|
+
# MATTHEW E. SHEIE ERICSON
|
431
|
+
elsif name.match( /^([#{@nc}]+) ([A-Za-z])\.? ($multNamePat)$/i )
|
432
|
+
first = $1;
|
433
|
+
middle = $2;
|
434
|
+
last = $3;
|
435
|
+
parsed = true
|
436
|
+
parse_type = 11;
|
437
|
+
end
|
438
|
+
|
439
|
+
last.gsub!( /;/, "" )
|
440
|
+
|
441
|
+
return [ parsed, parse_type, first, middle, last ];
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
def proper ( name )
|
448
|
+
|
449
|
+
fixed = name.downcase
|
450
|
+
|
451
|
+
# Now uppercase first letter of every word. By checking on word boundaries,
|
452
|
+
# we will account for apostrophes (D'Angelo) and hyphenated names
|
453
|
+
fixed.gsub!( /\b(\w+)/ ) { |m| m.match( /^[ixv]$+/i ) ? m.upcase : m.capitalize }
|
454
|
+
|
455
|
+
# Name case Macs and Mcs
|
456
|
+
# Exclude names with 1-2 letters after prefix like Mack, Macky, Mace
|
457
|
+
# Exclude names ending in a,c,i,o,z or j, typically Polish or Italian
|
458
|
+
|
459
|
+
if fixed.match( /\bMac[a-z]{2,}[^a|c|i|o|z|j]\b/i )
|
460
|
+
|
461
|
+
fixed.gsub!( /\b(Mac)([a-z]+)/i ) do |m|
|
462
|
+
$1 + $2.capitalize
|
463
|
+
end
|
464
|
+
|
465
|
+
# Now correct for "Mac" exceptions
|
466
|
+
fixed.gsub!( /MacHin/i, 'Machin' )
|
467
|
+
fixed.gsub!( /MacHlin/i, 'Machlin' )
|
468
|
+
fixed.gsub!( /MacHar/i, 'Machar' )
|
469
|
+
fixed.gsub!( /MacKle/i, 'Mackle' )
|
470
|
+
fixed.gsub!( /MacKlin/i, 'Macklin' )
|
471
|
+
fixed.gsub!( /MacKie/i, 'Mackie' )
|
472
|
+
|
473
|
+
# Portuguese
|
474
|
+
fixed.gsub!( /MacHado/i, 'Machado' );
|
475
|
+
|
476
|
+
# Lithuanian
|
477
|
+
fixed.gsub!( /MacEvicius/i, 'Macevicius' )
|
478
|
+
fixed.gsub!( /MacIulis/i, 'Maciulis' )
|
479
|
+
fixed.gsub!( /MacIas/i, 'Macias' )
|
480
|
+
|
481
|
+
elsif fixed.match( /\bMc/i )
|
482
|
+
fixed.gsub!( /\b(Mc)([a-z]+)/i ) do |m|
|
483
|
+
$1 + $2.capitalize
|
484
|
+
end
|
485
|
+
|
486
|
+
end
|
487
|
+
|
488
|
+
# Exceptions (only 'Mac' name ending in 'o' ?)
|
489
|
+
fixed.gsub!( /Macmurdo/i, 'MacMurdo' )
|
490
|
+
|
491
|
+
return fixed
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
|
498
|
+
end
|
499
|
+
|
data/people.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
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}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthew Ericson"]
|
12
|
+
s.date = %q{2010-10-29}
|
13
|
+
s.email = %q{mericson@ericson.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"lib/people.rb",
|
26
|
+
"people.gemspec",
|
27
|
+
"test/people_test.rb",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/mericson/people}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{Matts Name Parser}
|
35
|
+
s.test_files = [
|
36
|
+
"test/people_test.rb",
|
37
|
+
"test/test_helper.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/test/people_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: people
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matthew Ericson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-29 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: mericson@ericson.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- VERSION.yml
|
38
|
+
- lib/people.rb
|
39
|
+
- people.gemspec
|
40
|
+
- test/people_test.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/mericson/people
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.7
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Matts Name Parser
|
76
|
+
test_files:
|
77
|
+
- test/people_test.rb
|
78
|
+
- test/test_helper.rb
|