Class: Juscribe::Name
- Inherits:
-
Object
- Object
- Juscribe::Name
- Defined in:
- lib/juscribe/name.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.
Class Method Summary collapse
Instance Method Summary collapse
- #complete ⇒ Object
- #first_and_last ⇒ Object
- #full ⇒ Object
-
#initialize(first, *others, last) ⇒ Name
constructor
A new instance of Name.
- #inspect ⇒ Object
- #middle_initial ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(first, *others, last) ⇒ Name
Returns a new instance of Name.
14 15 16 |
# File 'lib/juscribe/name.rb', line 14 def initialize(first, *others, last) @first, @middle, @last = first, others.first, last end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
3 4 5 |
# File 'lib/juscribe/name.rb', line 3 def first @first end |
#last ⇒ Object (readonly)
Returns the value of attribute last.
3 4 5 |
# File 'lib/juscribe/name.rb', line 3 def last @last end |
#middle ⇒ Object (readonly)
Returns the value of attribute middle.
3 4 5 |
# File 'lib/juscribe/name.rb', line 3 def middle @middle end |
Class Method Details
.convert(input) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/juscribe/name.rb', line 6 def convert(input) case input when String new(*input.split(/\s+/)) end end |
Instance Method Details
#complete ⇒ Object
30 31 32 |
# File 'lib/juscribe/name.rb', line 30 def complete [first, *middle, *last].join(' ') end |
#first_and_last ⇒ Object
22 23 24 |
# File 'lib/juscribe/name.rb', line 22 def first_and_last [first, *last].join(' ') end |
#full ⇒ Object
26 27 28 |
# File 'lib/juscribe/name.rb', line 26 def full [first, *middle_initial, *last].join(' ') end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/juscribe/name.rb', line 38 def inspect %Q{"#{complete}"} end |
#middle_initial ⇒ Object
18 19 20 |
# File 'lib/juscribe/name.rb', line 18 def middle_initial "#{middle.first}." if middle.present? end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/juscribe/name.rb', line 34 def to_s full end |