Module: FullNameSplitter
- Defined in:
- lib/full-name-splitter.rb
Overview
requires full accessable first_name and last_name attributes
Defined Under Namespace
Classes: Splitter
Constant Summary collapse
- PREFIXES =
%w(de da la du del dei vda. dello della degli delle van von der den heer ten ter vande vanden vander voor ver aan mc ben).freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.split(name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/full-name-splitter.rb', line 91 def split(name) name = name.to_s.strip.gsub(/\s+/, ' ') if name.include?(',') name. split(/\s*,\s*/, 2). # ",van helsing" produces ["", "van helsing"] map{ |u| u.empty? ? nil : u } # but it should be [nil, "van helsing"] by lib convection else splitter = Splitter.new(name) [splitter.first_name, splitter.last_name] end end |
Instance Method Details
#full_name ⇒ Object
81 82 83 |
# File 'lib/full-name-splitter.rb', line 81 def full_name [first_name, last_name].compact.join(' ') end |
#full_name=(name) ⇒ Object
85 86 87 |
# File 'lib/full-name-splitter.rb', line 85 def full_name=(name) self.first_name, self.last_name = split(name) end |