Class: FullNameSplitter::Splitter
- Inherits:
-
Object
- Object
- FullNameSplitter::Splitter
- Defined in:
- lib/full-name-splitter.rb
Instance Method Summary collapse
- #first_name ⇒ Object
-
#initialize(full_name) ⇒ Splitter
constructor
A new instance of Splitter.
- #last_name ⇒ Object
- #split! ⇒ Object
Constructor Details
#initialize(full_name) ⇒ Splitter
Returns a new instance of Splitter.
9 10 11 12 13 14 |
# File 'lib/full-name-splitter.rb', line 9 def initialize(full_name) @full_name = full_name @first_name = [] @last_name = [] split! end |
Instance Method Details
#first_name ⇒ Object
30 31 32 |
# File 'lib/full-name-splitter.rb', line 30 def first_name @first_name.empty? ? nil : @first_name.join(' ') end |
#last_name ⇒ Object
34 35 36 |
# File 'lib/full-name-splitter.rb', line 34 def last_name @last_name.empty? ? nil : @last_name.join(' ') end |
#split! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/full-name-splitter.rb', line 16 def split! @units = @full_name.split(/\s+/) while @unit = @units.shift do if prefix? or with_apostrophe? or (first_name? and last_unit? and not initial?) @last_name << @unit and break else @first_name << @unit end end @last_name += @units adjust_exceptions! end |