human_name_parser 0.0.3 → 0.0.4
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/lib/human_name_parser/name.rb +11 -1
- data/lib/human_name_parser/version.rb +1 -1
- data/spec/name_spec.rb +11 -0
- metadata +3 -3
@@ -106,7 +106,12 @@ module HumanNameParser
|
|
106
106
|
# this is a thing that I cannot recognize
|
107
107
|
@split_name = []
|
108
108
|
elsif @input_string.count(",") == 1
|
109
|
-
@
|
109
|
+
if suffix_follows_comma?(@input_string)
|
110
|
+
# remove commas from the split
|
111
|
+
@split_name = split_first_middle_last.map {|n| n.gsub(',', '')}
|
112
|
+
else
|
113
|
+
@split_name = split_last_comma_first_middle
|
114
|
+
end
|
110
115
|
else
|
111
116
|
@split_name = split_first_middle_last
|
112
117
|
end
|
@@ -114,6 +119,11 @@ module HumanNameParser
|
|
114
119
|
return self
|
115
120
|
end
|
116
121
|
|
122
|
+
# check whether each part is a suffix
|
123
|
+
def suffix_follows_comma? name
|
124
|
+
name.split(',')[1].split(' ').all? {|part| is_suffix?(part)}
|
125
|
+
end
|
126
|
+
|
117
127
|
def split_last_comma_first_middle
|
118
128
|
match = @input_string.match(",")
|
119
129
|
normalized = ""
|
data/spec/name_spec.rb
CHANGED
@@ -45,6 +45,17 @@ describe HumanNameParser::Name do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context "when full name is Marley Mante, esq." do
|
49
|
+
let(:full_name) { "Marley Mante, esq." }
|
50
|
+
it "should parse the name" do
|
51
|
+
@name = HumanNameParser::Name.new full_name
|
52
|
+
@name.first.should == 'Marley'
|
53
|
+
@name.last.should == 'Mante'
|
54
|
+
@name.middle.should == ''
|
55
|
+
@name.suffix.should == 'esq.'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
48
59
|
context 'when full name is Mary Lou Smith' do
|
49
60
|
let(:full_name) { "Mary Lou Smith" }
|
50
61
|
before do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: human_name_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Bachman
|