public
Description: Gem for parsing names into first, last, middle, prefix and suffix
Clone URL: git://github.com/bricooke/name_parser.git
Search Repo:
first commit
Brian Cooke (author)
Tue Feb 26 16:00:22 -0800 2008
commit  e41b49e25b8f1ad59ba3729875e1685c92151c05
tree    5e3d7a700e856c331479df8207884b7b2c3504da
...
 
 
 
 
 
...
1
2
3
4
5
0
@@ -0,0 +1,5 @@
0
+=== 1.0.0 / 2008-02-26
0
+
0
+* 1 major enhancement
0
+ * Birthday!
0
+
...
 
 
 
 
 
 
...
1
2
3
4
5
6
0
@@ -0,0 +1,6 @@
0
+History.txt
0
+Manifest.txt
0
+README.txt
0
+Rakefile
0
+lib/name_parser.rb
0
+test/test_name_parser.rb
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -0,0 +1,48 @@
0
+= name_parser
0
+
0
+https://roobasoft.roundhaus.com/projects/383-gems/name_parser
0
+
0
+== DESCRIPTION:
0
+
0
+Provides a NameParser class that takes a single string and provides .first_name, .last_name, .initial functions for the parsed name
0
+
0
+== FEATURES/PROBLEMS:
0
+
0
+* FIX (list of features or problems)
0
+
0
+== SYNOPSIS:
0
+
0
+ FIX (code sample of usage)
0
+
0
+== REQUIREMENTS:
0
+
0
+* FIX (list of requirements)
0
+
0
+== INSTALL:
0
+
0
+* FIX (sudo gem install, anything else)
0
+
0
+== LICENSE:
0
+
0
+(The MIT License)
0
+
0
+Copyright (c) 2008 Makalumedia
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+'Software'), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -0,0 +1,17 @@
0
+# -*- ruby -*-
0
+
0
+require 'rubygems'
0
+require 'hoe'
0
+require './lib/name_parser.rb'
0
+
0
+Hoe.new('name_parser', NameParser::VERSION) do |p|
0
+ p.rubyforge_name = 'name_parser'
0
+ p.author = 'Brian Cooke'
0
+ p.email = 'brian.cooke@makalumedia.com'
0
+ p.summary = 'Parse a given string into parts of a name'
0
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
0
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
0
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
0
+end
0
+
0
+# vim: syntax=Ruby
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -0,0 +1,57 @@
0
+class NameParser
0
+ VERSION = '0.1.1'
0
+
0
+ attr_reader :first_name, :last_name, :middle_name, :prefix, :suffix
0
+
0
+ PREFIXES = [/^mr[\.]?/i, /^mrs[\.]?/i, /^miss/i, /^mister/i, /^dr[\.]?/i, /^mr[\.]? and mrs[\.]?/i, /^mrs[\.]? and mr[\.]?/i]
0
+ SUFFIXES = [/,?\s*jr[\.]?$/i, /,?\s*sr[\.]?$/i, /,?\s*iii$/i, /,?\s*iv$/i, /,?\s*v$/i, /,?\s*phd$/i]
0
+ LAST_NAME_PREFIXES = [/de la /i]
0
+
0
+ def initialize(string)
0
+ @initial_string = string
0
+ @first_name = @last_name = @middle_name = @prefix = @suffix = ""
0
+ @working_string = string
0
+
0
+ remove_current_resident
0
+ find_prefix
0
+ find_suffix
0
+ find_first_name
0
+ find_last_name
0
+ find_middle_name
0
+ end
0
+
0
+ def remove_current_resident
0
+ @working_string = @working_string.gsub(/(or)?\s*current resident/i, "")
0
+ end
0
+
0
+ def find_prefix
0
+ PREFIXES.each do |prefix|
0
+ @prefix = prefix.match(@working_string)[0] rescue ""
0
+ break unless @prefix.empty?
0
+ end
0
+ @working_string = @working_string.gsub(@prefix, "").strip
0
+ end
0
+
0
+ def find_first_name
0
+ @first_name = @working_string.split(" ")[0] || ""
0
+ @working_string = @working_string.gsub(@first_name, "").strip
0
+ end
0
+
0
+ def find_last_name
0
+ @last_name = @working_string.split(" ")[-1] || ""
0
+ @working_string = @working_string.gsub(@last_name, "").strip
0
+ end
0
+
0
+ def find_middle_name
0
+ @middle_name = @working_string.strip
0
+ end
0
+
0
+ def find_suffix
0
+ SUFFIXES.each do |suffix|
0
+ @suffix = suffix.match(@working_string)[0] rescue ""
0
+ break unless @suffix.empty?
0
+ end
0
+ @working_string = @working_string.gsub(@suffix, "").strip
0
+ @suffix = @suffix.gsub(/,?\s*/, "").strip
0
+ end
0
+end
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -0,0 +1,61 @@
0
+require 'lib/name_parser.rb'
0
+
0
+describe "NameParser" do
0
+ it "should parse a simple first and last name" do
0
+ test [
0
+ ["Brian Cooke", {:first_name => "Brian", :last_name => "Cooke"}]
0
+ ]
0
+ end
0
+
0
+ it "should parse out prefixes" do
0
+ test [
0
+ ["Mr. Brian Cooke", {:prefix => "Mr.", :first_name => "Brian", :last_name => "Cooke"}]
0
+ ]
0
+ end
0
+
0
+ it "should parse out suffixes" do
0
+ test [
0
+ ["Dinosaur Jr.", {:first_name => "Dinosaur", :suffix => "Jr."}],
0
+ ["Mr. Brian Cooke, III", {:prefix => "Mr.", :first_name => "Brian", :last_name => "Cooke", :suffix => "III"}]
0
+ ]
0
+ end
0
+
0
+ it "should parse out middle initials and names" do
0
+ test [
0
+ ["Brian Thomas Cooke", {:first_name => "Brian", :middle_name => "Thomas", :last_name => "Cooke"}],
0
+ ["Bob W. Dilan", {:first_name => "Bob", :middle_name => "W.", :last_name => "Dilan"}]
0
+ ]
0
+ end
0
+
0
+ # TODO: Beef this up so we can detect multiple names and handle them accordingly
0
+ it "should handle multiple names reasonably" do
0
+ test [
0
+ ["Emily & Drue Jennings", {:first_name => "Emily", :last_name => "Jennings"}],
0
+ ["Parrish & Reinish", {:first_name => "Parrish", :last_name => "Reinish"}],
0
+ ["Elaine and Abe Kleiman", {:first_name => "Elaine", :last_name => "Kleiman"}],
0
+ ["Mark or Joyce Barker", {:first_name => "Mark", :last_name => "Barker"}]
0
+ ]
0
+ end
0
+
0
+ it "should ignore Current Resident" do
0
+ test [
0
+ ["Current Resident", {:first_name => "", :last_name => ""}],
0
+ ["Brian Cooke or Current Resident", {:first_name => "Brian", :last_name => "Cooke"}]
0
+ ]
0
+ end
0
+
0
+ it "should not modify the input string" do
0
+ test = "Current Resident"
0
+ n = NameParser.new(test)
0
+ test.should == "Current Resident"
0
+ end
0
+
0
+ def test(array)
0
+ array.each do |test|
0
+ parser = NameParser.new(test[0])
0
+ test[1].keys.each do |key|
0
+ parser.send(key).should == test[1][key]
0
+ end
0
+ end
0
+ end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.