Git Product home page Git Product logo

full-name-splitter's Introduction

#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.

full-name-splitter's People

Contributors

pahanix avatar michaelklishin avatar

Watchers

brucexlin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.