Class: NameSplitter::Splitter
- Inherits:
-
Object
- Object
- NameSplitter::Splitter
- Defined in:
- lib/name_splitter.rb
Instance Attribute Summary collapse
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#last_name_prefix ⇒ Object
writeonly
Sets the attribute last_name_prefix.
-
#middle_name ⇒ Object
Returns the value of attribute middle_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#salutation ⇒ Object
Returns the value of attribute salutation.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
-
#suffixes ⇒ Object
writeonly
Sets the attribute suffixes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fullname = "") ⇒ Splitter
constructor
A new instance of Splitter.
- #last_name_check(last_name_arr) ⇒ Object
Constructor Details
#initialize(fullname = "") ⇒ Splitter
Returns a new instance of Splitter.
12 13 14 15 16 17 18 19 |
# File 'lib/name_splitter.rb', line 12 def initialize(fullname = "") self.salutation = "" self.first_name = "" self.middle_name = "" self.last_name = "" self.suffix = "" self.name = fullname if fullname and !fullname.to_s.empty? end |
Instance Attribute Details
#first_name ⇒ Object
Returns the value of attribute first_name.
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def first_name @first_name end |
#last_name ⇒ Object
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def last_name @last_name end |
#last_name_prefix=(value) ⇒ Object
Sets the attribute last_name_prefix
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def last_name_prefix=(value) @last_name_prefix = value end |
#middle_name ⇒ Object
Returns the value of attribute middle_name.
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def middle_name @middle_name end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/name_splitter.rb', line 6 def name @name end |
#salutation ⇒ Object
Returns the value of attribute salutation.
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def salutation @salutation end |
#suffix ⇒ Object
Returns the value of attribute suffix.
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def suffix @suffix end |
#suffixes=(value) ⇒ Object
Sets the attribute suffixes
5 6 7 |
# File 'lib/name_splitter.rb', line 5 def suffixes=(value) @suffixes = value end |
Class Method Details
.call(fullname) ⇒ Object
8 9 10 |
# File 'lib/name_splitter.rb', line 8 def self.call(fullname) new(fullname) end |
Instance Method Details
#last_name_check(last_name_arr) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/name_splitter.rb', line 48 def last_name_check(last_name_arr) #accepts either a string or an array if last_name_arr.class.name == "String" last_name_arr = last_name_arr.split(" ") end return false if last_name_arr.empty? self.suffix = last_name_arr.pop if contains_suffix(last_name_arr) self.last_name = last_name_arr.join(" ").gsub(/[.,]+/, "") end |