FullNameSplitter
FullNameSplitter splits full name into first and last name considering name prefixes and initials
If you include the module it requires attribute accessors first_name and last_name and adds #full_name, #full_name= to the class
For example
require 'full_name_splitter'
class Incognito
include FullNameSplitter
attr_accessor :first_name, :last_name
end
incognito = Incognito.new :full_name => "George H. W. Bush"
incognito.first_name # => "George H. W."
incognito.last_name # => "Bush"
incognito = Incognito.new :full_name => "Kevin J. O'Connor"
incognito.first_name # => "Kevin J."
incognito.last_name # => "O'Connor"
incognito = Incognito.new :full_name => "Thomas G. Della Fave"
incognito.first_name # => "Thomas G."
incognito.last_name # => "Della Fave"
incognito = Incognito.new :full_name => "Gabriel Van Helsing"
incognito.first_name # => "Gabriel"
incognito.last_name # => "Van Helsing"
If full name isn't complete FullNameSplitter tries to split partially
incognito = Incognito.new :full_name => "George W."
incognito.first_name # => "George W."
incognito.last_name # => nil
incognito = Incognito.new :full_name => "George"
incognito.first_name # => "George"
incognito.last_name # => nil
incognito = Incognito.new :full_name => "Van Helsing"
incognito.first_name # => nil
incognito.last_name # => "Van Helsing"
incognito = Incognito.new :full_name => "d'Artagnan"
incognito.first_name # => nil
incognito.last_name # => "d'Artagnan"
For other examples see spec/lib/full_name_splitter_spec.rb
Also you can use splitter directly by calling module function FullNameSplitter::split
FullNameSplitter.split("Juan Martín de la Cruz Gómez") # => ["Juan Martín", "de la Cruz Gómez"]
FullNameSplitter.split("Ludwig Mies van der Rohe") # => ["Ludwig", "Mies van der Rohe"]
If the lib can't split a name correctly, it is possible to split by comma
FullNameSplitter.split("John Quincy Adams") # => ["John Quincy", "Adams"]
FullNameSplitter.split("John, Quincy Adams") # => ["John", "Quincy Adams"]
Copyright
Created by Pavel Gorbokon. Contributed by Michael S. Klishin and Trevor Creech. Released under the MIT license.