Lib splits full name into first and last name considering name prefixes and initials
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 15 commits behind pahanix:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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

incognito = :full_name => "George H. W. Bush"
incognito.first_name # => "George H. W."
incognito.last_name  # => "Bush"

incognito = :full_name => "Kevin J. O'Connor"
incognito.first_name # => "Kevin J."
incognito.last_name  # => "O'Connor"

incognito = :full_name => "Thomas G. Della Fave"
incognito.first_name # => "Thomas G."
incognito.last_name  # => "Della Fave"

incognito = :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 = :full_name => "George W."
incognito.first_name # => "George W."
incognito.last_name  # => nil

incognito = :full_name => "George"
incognito.first_name # => "George"
incognito.last_name  # => nil

incognito = :full_name => "Van Helsing"
incognito.first_name # => nil
incognito.last_name  # => "Van Helsing"

incognito = :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"]