namor 0.2.1 → 0.3.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/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .DS_Store
19
+ .irb_history
data/lib/namor/namor.rb CHANGED
@@ -17,9 +17,9 @@ class Namor::Namor
17
17
  # * squeeze whitespace & trim spaces from ends
18
18
  def scrub(name, opts = {})
19
19
  suppression_list = @config[:suppress] || []
20
- suppression_re = (suppression_list + (opts[:suppress]||[])).compact.map(&:upcase).join('|')
20
+ suppression_re = Regexp.new('\b?' + (suppression_list + (opts[:suppress]||[])).compact.map(&:upcase).join('|') + '\b?')
21
21
 
22
- name && name.upcase.gsub(/^[ZX]{2,}/, '').gsub(/\b(#{suppression_re})\b/i, '').gsub(/\b(JR|SR|II|III|IV)\b/i, '').gsub(/\([^\(]*\)/, '').gsub(/\./, ' ').gsub(/[_'-]/, '').gsub(/,\s*$/, '').gsub(/ +/, ' ').strip
22
+ name && name.upcase.gsub(/^[ZX]{2,}/, '').gsub(suppression_re, '').gsub(/\b(JR|SR|II|III|IV)\b/i, '').gsub(/\([^\(]*\)/, '').gsub(/\./, ' ').gsub(/[_'\&-]/, '').gsub(/,\s*$/, '').gsub(/ +/, ' ').strip
23
23
  end
24
24
 
25
25
  def extract(name, opts = {})
data/lib/namor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Namor
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -5,7 +5,7 @@ require "spec_helper"
5
5
  describe "name extract" do
6
6
  before(:all) do
7
7
  @namor = Namor::Namor.new
8
- @namor.config(:suppress => ['MD', 'dds'])
8
+ @namor.config(:suppress => ['MD', 'dds', 'M\.D\.'])
9
9
  end
10
10
 
11
11
  it "should handle 2-part names without commas" do
@@ -36,10 +36,12 @@ describe "name extract" do
36
36
  @namor.extract("Smith Jones, Mary").should == ['MARY', nil, 'SMITHJONES', 'SMITHJONES,MARY']
37
37
  end
38
38
 
39
- it "should drop dashes & apostrophes" do
39
+ it "should drop dashes, apostrophes, ampersands" do
40
40
  @namor.extract("Mary Smith-Jones").should == ['MARY', nil, 'SMITHJONES', 'SMITHJONES,MARY']
41
41
  @namor.extract("Mary S. O'Keefe").should == ['MARY', 'S', 'OKEEFE', 'OKEEFE,MARY S']
42
42
  @namor.extract("Jean-Michel Claude").should == ['JEANMICHEL', nil, 'CLAUDE', 'CLAUDE,JEANMICHEL']
43
+ @namor.extract("Smith, Bob & Sue").should == ['BOB', 'SUE', 'SMITH', 'SMITH,BOB SUE']
44
+ @namor.extract("Research & Development").should == ['RESEARCH', nil, 'DEVELOPMENT', 'DEVELOPMENT,RESEARCH']
43
45
  end
44
46
 
45
47
  it "should concatenate extract name pieces" do
@@ -53,6 +55,7 @@ describe "name extract" do
53
55
 
54
56
  it "should excise terms from optional suppression list" do
55
57
  @namor.extract("Smith Jr, Edward M MD DDS").should == ['EDWARD', 'M', 'SMITH', 'SMITH,EDWARD M']
58
+ @namor.extract("Smith Jr, Edward M M.D.").should == ['EDWARD', 'M', 'SMITH', 'SMITH,EDWARD M']
56
59
  @namor.extract("Smith Jr, Edward III MD PHD").should == ['EDWARD', 'PHD', 'SMITH', 'SMITH,EDWARD PHD']
57
60
  end
58
61
 
@@ -124,5 +127,8 @@ describe "name componentization" do
124
127
 
125
128
  it "should allow case-specific word suppression" do
126
129
  @namor.scrub("Amazing Magician", :suppress => ['magician', nil, 'conjuror']).should == 'AMAZING'
130
+ @namor.scrub("Jones, Susan Select Transcriptionist", :suppress => ['transcriptionist']).should == 'JONES, SUSAN SELECT'
131
+ @namor.scrub("Jones, Susan Select Transcriptionist", :suppress => ['select transcriptionist']).should == 'JONES, SUSAN'
132
+ @namor.scrub("Jones, Susan Select Transcriptionist", :suppress => ['transcriptionist', 'select transcriptionist']).should == 'JONES, SUSAN'
127
133
  end
128
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-31 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 3885137161130796956
111
+ hash: 236992470015496114
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: 3885137161130796956
120
+ hash: 236992470015496114
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.24