Module: UserNaming::User

Extended by:
ActiveSupport::Concern
Defined in:
lib/user_naming/user.rb

Instance Method Summary collapse

Instance Method Details

#first_nameString

First name.

The first name is always the first word of the name.

Returns:



10
11
12
# File 'lib/user_naming/user.rb', line 10

def first_name
  name.split.first
end

#first_name_last_initialString

The first name and the last initial.

If only one name, just the first name is returned.

Examples:

'Bilbo' will be 'B'
'Bilbo Foo Baggins' will be 'Bilbo B'

Returns:



67
68
69
70
71
72
73
# File 'lib/user_naming/user.rb', line 67

def first_name_last_initial
  if name.split.count > 1
    first_name + ' ' + last_name[0].upcase + '.'
  else
    first_name
  end
end

#initialsString

Initials.

The initials are the first letter of each name part, joined together without periods.

Examples:

'Bilbo' will have initials of 'B'.
'Bilbo Foo Baggins' will have initials of 'BFB'.
'Bilbo Bartlet Foo Baggins' will have initials of 'BBFB'.

Returns:



54
55
56
# File 'lib/user_naming/user.rb', line 54

def initials
  name.split.collect{|p| p[0].upcase }.join
end

#last_nameString

The last name.

A name with only one part will return an empty string. A name with two or more parts will return the last part.

Examples:

'Bilbo' will have a last name of ''.
'Bilbo Foo Baggins' will have a last name of 'Baggins'.

Returns:



35
36
37
38
39
40
41
# File 'lib/user_naming/user.rb', line 35

def last_name
  if name.split.count > 1
    name.split[-1]
  else
    ''
  end
end

#middle_nameString

Middle name.

The middle name is everything between the first name and last name, or empty string.

Returns:



21
22
23
# File 'lib/user_naming/user.rb', line 21

def middle_name
  name.split[1..-2].join(' ')
end