Class: Governator::NameParser
- Inherits:
-
Object
- Object
- Governator::NameParser
- Defined in:
- lib/governator/name_parser.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#last ⇒ Object
readonly
Returns the value of attribute last.
-
#middle ⇒ Object
readonly
Returns the value of attribute middle.
-
#nickname ⇒ Object
readonly
Returns the value of attribute nickname.
-
#official_full ⇒ Object
readonly
Returns the value of attribute official_full.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
Instance Method Summary collapse
- #detect_nickname ⇒ Object
- #detect_suffix ⇒ Object
-
#initialize(official_full) ⇒ NameParser
constructor
A new instance of NameParser.
- #name_array ⇒ Object
- #parse ⇒ Object
- #set_first_and_last ⇒ Object
- #set_first_last_and_middle ⇒ Object
- #set_name_with_initialed_first ⇒ Object
- #split_name ⇒ Object
Constructor Details
#initialize(official_full) ⇒ NameParser
Returns a new instance of NameParser.
7 8 9 |
# File 'lib/governator/name_parser.rb', line 7 def initialize(official_full) @official_full = official_full end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def last @last end |
#middle ⇒ Object (readonly)
Returns the value of attribute middle.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def middle @middle end |
#nickname ⇒ Object (readonly)
Returns the value of attribute nickname.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def nickname @nickname end |
#official_full ⇒ Object (readonly)
Returns the value of attribute official_full.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def official_full @official_full end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
5 6 7 |
# File 'lib/governator/name_parser.rb', line 5 def suffix @suffix end |
Instance Method Details
#detect_nickname ⇒ Object
49 50 51 52 |
# File 'lib/governator/name_parser.rb', line 49 def detect_nickname @nickname = name_array.detect { |name| name.include?('"') } name_array.reject! { |name| name.include?('"') } end |
#detect_suffix ⇒ Object
54 55 56 57 58 59 |
# File 'lib/governator/name_parser.rb', line 54 def detect_suffix @suffix = if name_array[-2].include?(',') name_array[-2].delete(',') name_array.pop end end |
#name_array ⇒ Object
16 17 18 |
# File 'lib/governator/name_parser.rb', line 16 def name_array @_name_array ||= official_full.split(' ') end |
#parse ⇒ Object
11 12 13 14 |
# File 'lib/governator/name_parser.rb', line 11 def parse split_name [first, last, middle, nickname, suffix] end |
#set_first_and_last ⇒ Object
32 33 34 35 |
# File 'lib/governator/name_parser.rb', line 32 def set_first_and_last @first = name_array.first @last = name_array.last end |
#set_first_last_and_middle ⇒ Object
43 44 45 46 47 |
# File 'lib/governator/name_parser.rb', line 43 def set_first_last_and_middle @first = name_array.shift @last = name_array.pop @middle = name_array.join(' ') end |
#set_name_with_initialed_first ⇒ Object
37 38 39 40 41 |
# File 'lib/governator/name_parser.rb', line 37 def set_name_with_initialed_first @first = "#{name_array.shift} #{name_array.shift}" @last = name_array.pop @middle = name_array.pop end |
#split_name ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/governator/name_parser.rb', line 20 def split_name detect_nickname detect_suffix if name_array.length == 2 set_first_and_last elsif name_array[0].include?('.') && name_array[1].include?('.') set_name_with_initialed_first elsif name_array.length >= 3 set_first_last_and_middle end end |