public
Description: Gem for parsing names into first, last, middle, prefix and suffix
Clone URL: git://github.com/bricooke/name_parser.git
Search Repo:
bricooke (author)
Wed Mar 26 22:30:59 -0700 2008
commit  a7274a8ffa1bd0612bd2b021a3ce7d3a92a66f51
tree    a739b61940613cc6605253e098341abdc23e6940
parent  e41b49e25b8f1ad59ba3729875e1685c92151c05
name_parser / spec / name_parser_spec.rb
100644 63 lines (55 sloc) 2.134 kb
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
63
require 'lib/name_parser.rb'
 
describe "NameParser" do
  it "should parse a simple first and last name" do
    test [
      ["Brian Cooke", {:first_name => "Brian", :last_name => "Cooke"}]
    ]
  end
  
  it "should parse out prefixes" do
    test [
      ["Mr. Brian Cooke", {:prefix => "Mr.", :first_name => "Brian", :last_name => "Cooke"}],
      ["Mrs. Brian Cooke", {:prefix => "Mrs.", :first_name => "Brian", :last_name => "Cooke"}],
      ["Mrs Brian Cooke", {:prefix => "Mrs", :first_name => "Brian", :last_name => "Cooke"}]
    ]
  end
  
  it "should parse out suffixes" do
    test [
      ["Dinosaur Jr.", {:first_name => "Dinosaur", :suffix => "Jr."}],
      ["Mr. Brian Cooke, III", {:prefix => "Mr.", :first_name => "Brian", :last_name => "Cooke", :suffix => "III"}]
    ]
  end
  
  it "should parse out middle initials and names" do
    test [
      ["Brian Thomas Cooke", {:first_name => "Brian", :middle_name => "Thomas", :last_name => "Cooke"}],
      ["Bob W. Dilan", {:first_name => "Bob", :middle_name => "W.", :last_name => "Dilan"}]
    ]
  end
  
  # TODO: Beef this up so we can detect multiple names and handle them accordingly
  it "should handle multiple names reasonably" do
    test [
      ["Emily & Drue Jennings", {:first_name => "Emily", :last_name => "Jennings"}],
      ["Parrish & Reinish", {:first_name => "Parrish", :last_name => "Reinish"}],
      ["Elaine and Abe Kleiman", {:first_name => "Elaine", :last_name => "Kleiman"}],
      ["Mark or Joyce Barker", {:first_name => "Mark", :last_name => "Barker"}]
    ]
  end
  
  it "should ignore Current Resident" do
    test [
      ["Current Resident", {:first_name => "", :last_name => ""}],
      ["Brian Cooke or Current Resident", {:first_name => "Brian", :last_name => "Cooke"}]
    ]
  end
  
  it "should not modify the input string" do
    test = "Current Resident"
    n = NameParser.new(test)
    test.should == "Current Resident"
  end
  
  def test(array)
    array.each do |test|
      parser = NameParser.new(test[0])
      test[1].keys.each do |key|
        parser.send(key).should == test[1][key]
      end
    end
  end
end