module UserNaming::User

Public Instance Methods

first_name() click to toggle source

First name.

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

@return [String]

# File lib/user_naming/user.rb, line 10
def first_name
  name.split.first
end
first_name_last_initial() click to toggle source

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'

@return [String]

# 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
initials() click to toggle source

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'.

@return [String]

# File lib/user_naming/user.rb, line 54
def initials
  name.split.collect{|p| p[0].upcase }.join
end
last_name() click to toggle source

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'.

@return [String]

# File lib/user_naming/user.rb, line 35
def last_name
  if name.split.count > 1
    name.split[-1]
  else
    ''
  end
end
middle_name() click to toggle source

Middle name.

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

@return [String]

# File lib/user_naming/user.rb, line 21
def middle_name
  name.split[1..-2].join(' ')
end