Class: Juscribe::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/juscribe/name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#firstObject (readonly)

Returns the value of attribute first.



3
4
5
# File 'lib/juscribe/name.rb', line 3

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



3
4
5
# File 'lib/juscribe/name.rb', line 3

def last
  @last
end

#middleObject (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

#completeObject



30
31
32
# File 'lib/juscribe/name.rb', line 30

def complete
  [first, *middle, *last].join(' ')
end

#first_and_lastObject



22
23
24
# File 'lib/juscribe/name.rb', line 22

def first_and_last
  [first, *last].join(' ')
end

#fullObject



26
27
28
# File 'lib/juscribe/name.rb', line 26

def full
  [first, *middle_initial, *last].join(' ')
end

#inspectObject



38
39
40
# File 'lib/juscribe/name.rb', line 38

def inspect
  %Q{"#{complete}"}
end

#middle_initialObject



18
19
20
# File 'lib/juscribe/name.rb', line 18

def middle_initial
  "#{middle.first}." if middle.present?
end

#to_sObject



34
35
36
# File 'lib/juscribe/name.rb', line 34

def to_s
  full
end