namor 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/namor/namor.rb CHANGED
@@ -55,6 +55,19 @@ class Namor::Namor
55
55
  end
56
56
  end
57
57
 
58
+ def assemble(firstname, middlename, lastname, de_maidened_last)
59
+ firstname = final_cleaning(firstname)
60
+ middlename = final_cleaning(middlename)
61
+ lastname = final_cleaning(lastname)
62
+ de_maidened_last = final_cleaning(de_maidened_last)
63
+
64
+ fm = [firstname, middlename].compact.join(' ')
65
+ fullname = [lastname, fm].compact.join(',')
66
+ nee_fullname = [de_maidened_last, fm].compact.join(',')
67
+
68
+ [firstname, middlename, lastname, fullname, nee_fullname]
69
+ end
70
+
58
71
  def extract(name, opts = {})
59
72
  return [] if name.nil?
60
73
 
@@ -84,16 +97,7 @@ class Namor::Namor
84
97
  lastname, de_maidened_last = demaiden(pieces.join(' '))
85
98
  end
86
99
 
87
- firstname = final_cleaning(firstname)
88
- middlename = final_cleaning(middlename)
89
- lastname = final_cleaning(lastname)
90
- de_maidened_last = final_cleaning(de_maidened_last)
91
-
92
- fm = [firstname, middlename].compact.join(' ')
93
- fullname = [lastname, fm].compact.join(',')
94
- nee_fullname = [de_maidened_last, fm].compact.join(',')
95
-
96
- [firstname, middlename, lastname, fullname, nee_fullname]
100
+ assemble(firstname, middlename, lastname, de_maidened_last)
97
101
  end
98
102
 
99
103
  def extract_with_cluster(name, opts = {})
@@ -102,6 +106,25 @@ class Namor::Namor
102
106
  ary << ary[3].gsub(/\W/, '_')
103
107
  end
104
108
 
109
+ def extract_from_pieces(hash)
110
+ assemble(
111
+ scrub(hash[:first]),
112
+ scrub(hash[:middle]),
113
+ scrub(hash[:last].upcase),
114
+ scrub(demaiden(hash[:last].upcase).last)
115
+ )
116
+ end
117
+
118
+ def extract_from_pieces_with_cluster(hash)
119
+ ary = assemble(
120
+ scrub(hash[:first]),
121
+ scrub(hash[:middle]),
122
+ scrub(hash[:last].upcase),
123
+ scrub(demaiden(hash[:last].upcase).last)
124
+ )
125
+ ary << ary[3].gsub(/\W/, '_')
126
+ ary << ary[4].gsub(/\W/, '_')
127
+ end
105
128
 
106
129
  def components(*args)
107
130
  suppression_list = @config[:suppress] ? @config[:suppress].map(&:upcase) : []
data/lib/namor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Namor
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -80,6 +80,15 @@ describe "name extract" do
80
80
  @namor.extract("Jones-De Quento, Maria").should == ['MARIA', nil, 'JONESDEQUENTO', 'JONESDEQUENTO,MARIA', 'DEQUENTO,MARIA']
81
81
  @namor.extract_with_cluster("Jones-De Quento, Maria").should == ['MARIA', nil, 'JONESDEQUENTO', 'JONESDEQUENTO,MARIA', 'DEQUENTO,MARIA', 'JONESDEQUENTO_MARIA']
82
82
  end
83
+
84
+ it "should build pieces from input components" do
85
+ @namor.extract_from_pieces(:first => 'John', :middle => 'M', :last => 'Smith').should == ['JOHN', 'M', 'SMITH', 'SMITH,JOHN M', 'SMITH,JOHN M']
86
+ @namor.extract_from_pieces(:first => 'Susan', :last => 'Smith-Jones').should == ['SUSAN', nil, 'SMITHJONES', 'SMITHJONES,SUSAN', 'JONES,SUSAN']
87
+
88
+ @namor.extract_from_pieces_with_cluster(:first => 'John', :middle => 'M', :last => 'Smith').should == ['JOHN', 'M', 'SMITH', 'SMITH,JOHN M', 'SMITH,JOHN M', 'SMITH_JOHN_M', 'SMITH_JOHN_M']
89
+ @namor.extract_from_pieces_with_cluster(:first => 'Susan', :last => 'Smith-Jones').should == ['SUSAN', nil, 'SMITHJONES', 'SMITHJONES,SUSAN', 'JONES,SUSAN', 'SMITHJONES_SUSAN', 'JONES_SUSAN']
90
+ end
91
+
83
92
  end
84
93
 
85
94
  describe "with cluster coding" do
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.4.2
4
+ version: 0.5.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-09-10 00:00:00.000000000 Z
12
+ date: 2012-09-11 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: 3058052180651373494
111
+ hash: -1676995470774616053
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: 3058052180651373494
120
+ hash: -1676995470774616053
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.24