name-tamer 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93cfcd5765b0b8ea84c41b3648bb45929a1cee52
4
- data.tar.gz: 0a43481b5c7d7f20d85c13ce2f654e37f860fe19
3
+ metadata.gz: d9d031176a31322a699ed9f02e3a97a1abb7912e
4
+ data.tar.gz: 5766a13e3c2f89e229d5aea90cb352abbc01c670
5
5
  SHA512:
6
- metadata.gz: e24644fd3e9723045ada62d2a29eebfa4aaecd26f6b04c2f0eb90e2030a3a97f6ac5ff46e9f24cc9bb485178d1e12fb0eae8cd5e103cf841fe95742b3f05090b
7
- data.tar.gz: 6812d69683174b11c3173b1a371ad3543e65ced985984a3711e41a2c852533f687777f14b97fe6e343d48fb437d0d2839ac3b5515ce28042348eae4f4187bf9b
6
+ metadata.gz: cad1aa4c38e12fa50246246e68082001ee8369b6757478b84685b0508fd72503af0ab18d11a33c6176d7a7177e5edd362c9c0151d75ab558c7692efcfea3191a
7
+ data.tar.gz: 45a86b7650641c31e6244c97ef36843141321553a436be17403a31ce1bafd2441f5c1b44fdfe517d811b8f5174bf36ce4e57ecd2e2aad24de8ab6771d826c901
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- name-tamer (0.0.6)
4
+ name-tamer (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/doc/suffixes.csv CHANGED
@@ -253,3 +253,21 @@ IV,The Fourth,person,100,,2
253
253
  V,The Fifth,person,20,,1
254
254
  D.V.M.,Doctor of Veterinary Medecine,person,100,,6
255
255
  V.M.D.,Doctor of Veterinary Medecine,person,100,,6
256
+ M.I.E.T.,Member of the Institution of Engineering and Technology,person,100,,8
257
+ T.M.I.E.T.,Member of the Institution of Engineering and Technology,person,100,,10
258
+ F.I.E.T.,Fellow of the Institution of Engineering and Technology,person,100,,8
259
+ E.R.P.,Energy Risk Professional,person,100,,6
260
+ A.C.A.,Associate of the Institute of Chartered Accountants in England and Wales,person,100,United Kingdom,6
261
+ C.T.A.,Chartered Tax Adviser,person,100,,6
262
+ F.C.A.,Fellow of the Institute of Chartered Accountants in England and Wales,person,100,United Kingdom,6
263
+ M.Jur.,Master of Jurisprudence,person,100,United Kingdom,6
264
+ F.C.M.I.,Fellow of the Chartered Management Institute,person,100,United Kingdom,8
265
+ F.C.C.A.,Fellow of the Association of Chartered Certified Accountants,person,100,,8
266
+ A.C.C.A.,Association of Chartered Certified Accountants,person,100,,8
267
+ &. Cie.,,organization,100,,7
268
+ I.T.I.L. v3,,person,100,,7
269
+ P.M.P.,,person,100,,6
270
+ F.I.R.P.,,person,100,,8
271
+ C.Eng.,,person,100,,6
272
+ S/A,,organization,100,,3
273
+ Chartered F.C.S.I.,,person,100,,18
data/lib/name-tamer.rb CHANGED
@@ -207,8 +207,33 @@ class NameTamer
207
207
 
208
208
  def remove_middle_names
209
209
  if @contact_type == :person
210
- parts = @simple_name.split
211
- @simple_name = "#{parts[0]} #{parts[-1]}" if parts.count > 2
210
+ parts = @simple_name.split
211
+ first_name = nil
212
+ last_name = nil
213
+
214
+ # Find first usable name
215
+ parts.each_index do |i|
216
+ part = parts[i]
217
+
218
+ unless part.gsub(FILTER_COMPAT, '').empty?
219
+ first_name = part
220
+ parts = parts.slice(i + 1, parts.length) # don't use "slice!"
221
+ break
222
+ end
223
+ end
224
+
225
+ # Find last usable name
226
+ parts.reverse_each do |part|
227
+ unless part.gsub(FILTER_COMPAT, '').empty?
228
+ last_name = part
229
+ break
230
+ end
231
+ end
232
+
233
+ if first_name || last_name
234
+ separator = first_name && last_name ? ' ' : ''
235
+ @simple_name = "#{first_name}#{separator}#{last_name}"
236
+ end
212
237
  end
213
238
  end
214
239
 
@@ -372,9 +397,9 @@ class NameTamer
372
397
  # Then we change any whitespace into our separator character
373
398
  new_string.gsub!(/\s+/, sep)
374
399
 
375
- # Change any dots embedded in words to our separator character
400
+ # Change some characters embedded in words to our separator character
376
401
  # e.g. example.com -> example-com
377
- new_string.gsub!(/(?<!\s)\.(?!\s)/, sep)
402
+ new_string.gsub!(/(?<!\s)[\.\/](?!\s)/, sep)
378
403
 
379
404
  # Then we strip any other illegal characters out completely
380
405
  new_string.gsub!(filter, '')
@@ -393,6 +418,9 @@ class NameTamer
393
418
  # keyboard.
394
419
  new_string.gsub!(/[^\x00-\x7f]/u) { |char| APPROXIMATIONS[char] || char }
395
420
 
421
+ # Have we got anything left?
422
+ new_string = '_' if new_string.empty?
423
+
396
424
  # downcase any latin characters
397
425
  new_string.downcase
398
426
  end
@@ -478,7 +506,7 @@ class NameTamer
478
506
  FILTER_COMPAT = /[^#{ALPHA}#{DIGIT}\-_#{UCSCHAR}]/
479
507
 
480
508
  NAME_MODIFIERS = [
481
- 'Al', 'Ap', 'Ben', 'Dell[ae]', 'D[aeiou]', 'De[lr]', 'D[ao]s', 'El', 'La', 'L[eo]', 'V[ao]n', 'Of', 'St[\.]?'
509
+ 'Al', 'Ap', 'Ben', 'Dell[ae]', 'D[aeiou]', 'De[lrn]', 'D[ao]s', 'El', 'La', 'L[eo]', 'V[ao]n', 'Of', 'St[\.]?'
482
510
  ]
483
511
 
484
512
  COMPOUND_NAMES = [
@@ -509,8 +537,12 @@ class NameTamer
509
537
  },
510
538
  suffix: {
511
539
  person: [
512
- 'C.I.S.S.P.', 'B.Tech.', 'D.Phil.', 'B.Eng.', 'C.F.A.', 'D.B.E.', 'D.D.S.', 'D.V.M.', 'Eng.D.', 'M.B.A.', 'M.B.E.',
513
- 'M.E.P.', 'M.Eng.', 'M.S.P.', 'O.B.E.', 'P.M.C.', 'P.M.P.', 'P.S.P.', 'V.M.D.', 'B.Ed.', 'B.Sc.', 'Ed.D.', 'LL.B.',
540
+ 'Chartered F.C.S.I.',
541
+ 'C.I.S.S.P.', 'T.M.I.E.T.', 'A.C.C.A.', 'F.C.C.A.', 'F.C.M.I.', 'F.I.E.T.', 'F.I.R.P.', 'M.I.E.T.', 'B.Tech.',
542
+ 'D.Phil.', 'I.T.I.L. v3', 'B.Eng.', 'C.Eng.', 'M.Jur.', 'C.F.A.', 'D.B.E.',
543
+ 'D.D.S.', 'D.V.M.', 'Eng.D.', 'A.C.A.', 'C.T.A.', 'E.R.P.', 'F.C.A', 'M.B.A.', 'M.B.E.',
544
+ 'M.E.P.', 'M.Eng.', 'M.Jur.', 'M.S.P.', 'O.B.E.', 'P.M.C.', 'P.M.P.', 'P.S.P.', 'V.M.D.', 'B.Ed.', 'B.Sc.', 'Ed.D.',
545
+ 'LL.B.',
514
546
  'LL.D.', 'LL.M.', 'M.Ed.', 'M.Sc.', 'Ph.D.', 'B.A.', 'Esq.', 'J.D.', 'K.C.', 'M.A.', 'M.D.', 'M.P.', 'O.K.',
515
547
  'P.A.', 'Q.C.', 'III', 'Jr.', 'Sr.', 'II', 'IV', 'I', 'V'
516
548
  ],
@@ -524,7 +556,8 @@ class NameTamer
524
556
  'K.G.a.A.', 'L.L.L.P.', 'Ltd. Co.', 'Ltd. Co.', 'M.E.P.E.', 'n.y.r.t.', 'O.V.E.E.', 'P.E.E.C.', 'P.L.L.C.',
525
557
  'P.L.L.C.', 'S. en C.', 'S.a.p.a.', 'S.A.R.L.', 'S.à.R.L.', 'S.A.S.U.', 'S.C.e.I.', 'S.C.O.P.', 'S.C.p.A.',
526
558
  'S.C.R.I.', 'S.C.R.L.', 'S.M.B.A.', 'S.P.R.L.', 'Е.О.О.Д.', 'and Co.', 'Comm.V.', 'Limited', 'P. Ltd.',
527
- 'Part.G.', 'Sh.p.k.', '&. Co.', 'C.X.A.', 'd.n.o.', 'd.o.o.', 'E.A.D.', 'e.h.f.', 'E.P.E.', 'E.S.V.', 'F.C.P.',
559
+ 'Part.G.', 'Sh.p.k.', '&. Co.', '&. Cie.', 'C.X.A.', 'd.n.o.', 'd.o.o.', 'E.A.D.', 'e.h.f.', 'E.P.E.', 'E.S.V.',
560
+ 'F.C.P.',
528
561
  'F.I.E.', 'G.b.R.', 'G.I.E.', 'G.M.K.', 'G.S.K.', 'H.U.F.', 'K.D.A.', 'k.f.t.', 'k.h.t.', 'k.k.t.', 'L.L.C.',
529
562
  'L.L.P.', 'o.h.f.', 'O.H.G.', 'O.O.D.', 'O.y.j.', 'p.l.c.', 'P.S.U.', 'S.A.E.', 'S.A.S.', 'S.C.A.', 'S.C.E.',
530
563
  'S.C.S.', 'S.E.M.', 'S.E.P.', 's.e.s.', 'S.G.R.', 'S.N.C.', 'S.p.A.', 'S.P.E.', 'S.R.L.', 's.r.o.', 'Unltd.',
@@ -535,7 +568,7 @@ class NameTamer
535
568
  'Ltd.', 'N.K.', 'N.L.', 'N.V.', 'O.E.', 'O.G.', 'O.Ü.', 'O.y.', 'P.C.', 'p.l.', 'Pty.', 'PUP.', 'Pvt.', 'r.t.',
536
569
  'S.A.', 'S.D.', 'S.E.', 's.f.', 'S.L.', 'S.P.', 'S.s.', 'T.K.', 'T.Ü.', 'U.Ü.', 'Y.K.', 'А.Д.', 'І.П.', 'К.Д.',
537
570
  'ПУП.', 'С.Д.', 'בע"מ', '任意組合', '匿名組合', '合同会社', '合名会社', '合資会社', '有限会社', '有限公司', '株式会社',
538
- 'A/S', 'G/S', 'I/S', 'K/S', 'P/S'
571
+ 'A/S', 'G/S', 'I/S', 'K/S', 'P/S', 'S/A'
539
572
  ],
540
573
  before:ADFIX_JOINERS, after:'\\z'
541
574
  }
@@ -1,3 +1,3 @@
1
1
  class NameTamer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -77,7 +77,7 @@ describe NameTamer do
77
77
  { n:'Elazer Edelman, MD , PhD', t: :person, nn:'Elazer Edelman', sn:'Elazer Edelman', s:'elazer-edelman' },
78
78
  { n:'Judith M. O\'Brien', t: :person, nn:'Judith M. O\'Brien', sn:'Judith O\'Brien', s:'judith-obrien' },
79
79
  { n:'MORRISON, Van', t: :person, nn:'Van Morrison', sn:'Van Morrison', s:'van-morrison' },
80
- { n:'i/o Ventures', t: :organization, nn:'i/o Ventures', sn:'i/o Ventures', s:'io-ventures' },
80
+ { n:'i/o Ventures', t: :organization, nn:'i/o Ventures', sn:'i/o Ventures', s:'i-o-ventures' },
81
81
  { n:'C T Corporation System', t: :person, nn:'C.T. Corporation System', sn:'CT Corporation System', s:'ct-corporation-system'},
82
82
  { n:'C.T. Corporation System', t: :person, nn:'C.T. Corporation System', sn:'CT Corporation System', s:'ct-corporation-system'},
83
83
  { n:'CT Corporation System', t: :person, nn:'CT Corporation System', sn:'CT Corporation System', s:'ct-corporation-system'},
@@ -120,35 +120,38 @@ describe NameTamer do
120
120
  { n:'קובי ביטר', t: :organization, nn:'קובי ביטר', sn:'קובי ביטר', s:'קובי-ביטר' },
121
121
  { n:'الملاك الحارس', t: :organization, nn:'الملاك الحارس', sn:'الملاك الحارس', s:'الملاك-الحارس' },
122
122
  { n:'কবির হাসান', t: :organization, nn:'কবির হাসান', sn:'কবির হাসান', s:'কবির-হাসান' },
123
- { nn: '', sn: '', s: '' },
123
+ { nn: '', sn: '', s: '_' },
124
124
  { n:'Union Square Ventures', t: 'Organization', nn:'Union Square Ventures', sn:'Union Square Ventures', s:'union-square-ventures' },
125
125
  { n:'John Smith', t: 'Person', nn:'John Smith', sn:'John Smith', s:'john-smith' },
126
126
  { n:'John Smith', t: :nonsense, nn:'John Smith', sn:'John Smith', s:'john-smith' },
127
127
  { n:'John Smith', t: Kernel, nn:'John Smith', sn:'John Smith', s:'john-smith' },
128
128
  { n:'Ms Jane Smith', t: :person, nn:'Jane Smith', sn:'Jane Smith', s:'jane-smith' },
129
129
  { n:'example.com', t: :organization, nn:'example.com', sn:'example.com', s:'example-com' },
130
- { n:'Hermann Müller', t: :person, nn: 'Hermann Müller', sn: 'Hermann Müller', s:'hermann-muller'}
130
+ { n:'Hermann Müller', t: :person, nn: 'Hermann Müller', sn: 'Hermann Müller', s:'hermann-muller'},
131
+ { n:'b-to-v Partners AG', t: :organization, nn:'b-to-v Partners', sn:'b-to-v Partners', s:'b-to-v-partners' },
132
+ { n:'*', t: :person, nn: '*', sn: '*', s:'_'},
133
+ { n:'* *', t: :person, nn: '* *', sn: '* *', s:'_'},
134
+ { n:'* Olga *', t: :person, nn: '* Olga *', sn: 'Olga', s:'olga'},
135
+ { n:'* Olga Bedia García *', t: :person, nn: '* Olga Bedia García *', sn: 'Olga García', s:'olga-garcia'},
131
136
  ]
132
137
  end
133
138
 
134
- it "makes a slug from #{name}" do
139
+ it "makes a slug" do
135
140
  names.each do |name_data|
136
141
  name = name_data[:n]
137
- #-puts NameTamer[name, contact_type:name_data[:t]].simple_name # debug
138
142
  NameTamer[name, contact_type:name_data[:t]].slug.should == name_data[:s]
139
143
  end
140
144
  end
141
145
 
142
- it "makes a nice name from #{name}" do
146
+ it "makes a nice name" do
143
147
  names.each do |name_data|
144
148
  name = name_data[:n]
145
149
  nice_name = NameTamer[name, contact_type:name_data[:t]].nice_name
146
-
147
150
  nice_name.should == name_data[:nn]
148
151
  end
149
152
  end
150
153
 
151
- it "makes a searchable name from #{name}" do
154
+ it "makes a searchable name" do
152
155
  names.each do |name_data|
153
156
  name = name_data[:n]
154
157
  NameTamer[name, contact_type:name_data[:t]].simple_name.should == name_data[:sn]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: name-tamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto