Class: Faker::Name

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/name.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.female_first_nameString Also known as: first_name_women, feminine_name

Produces a random female first name.

Examples:

Faker::Name.female_first_name #=> "Natasha"

Returns:

  • (String)

Available since:

  • 1.9.1



75
76
77
# File 'lib/faker/default/name.rb', line 75

def female_first_name
  fetch('name.female_first_name')
end

.first_nameString

Produces a random first name.

Examples:

Faker::Name.first_name #=> "Kaci"

Returns:

  • (String)

Available since:

  • 0.9.0



43
44
45
46
47
48
49
# File 'lib/faker/default/name.rb', line 43

def first_name
  if parse('name.first_name').empty?
    fetch('name.first_name')
  else
    parse('name.first_name')
  end
end

.initials(number: 3) ⇒ String

Produces random initials.

Examples:

Faker::Name.initials            #=> "NJM"
Faker::Name.initials(number: 2) #=> "NM"

Parameters:

  • number (Integer) (defaults to: 3)

    Number of digits that the generated initials should have.

Returns:

  • (String)

Available since:

  • 1.8.5



147
148
149
# File 'lib/faker/default/name.rb', line 147

def initials(number: 3)
  (0...number).map { rand(65..90).chr }.join
end

.last_nameString Also known as: middle_name

Produces a random last name.

Examples:

Faker::Name.last_name #=> "Ernser"

Returns:

  • (String)

Available since:

  • 0.9.0



105
106
107
# File 'lib/faker/default/name.rb', line 105

def last_name
  parse('name.last_name')
end

.male_first_nameString Also known as: first_name_men, masculine_name

Produces a random male first name.

Examples:

Faker::Name.male_first_name #=> "Edward"

Returns:

  • (String)

Available since:

  • 1.9.1



60
61
62
# File 'lib/faker/default/name.rb', line 60

def male_first_name
  fetch('name.male_first_name')
end

.nameString

Produces a random name.

Examples:

Faker::Name.name #=> "Tyshawn Johns Sr."

Returns:

  • (String)

Available since:

  • 0.9.0



17
18
19
# File 'lib/faker/default/name.rb', line 17

def name
  parse('name.name')
end

.name_with_middleString

Produces a random name with middle name.

Examples:

Faker::Name.name_with_middle #=> "Aditya Elton Douglas"

Returns:

  • (String)

Available since:

  • 1.6.4



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

def name_with_middle
  parse('name.name_with_middle')
end

.neutral_first_nameString Also known as: first_name_neutral, gender_neutral_first_name

Produces a random gender neutral first name.

Examples:

Faker::Name.neutral_first_name #=> "Casey"

Returns:

  • (String)

Available since:

  • 2.13.0



90
91
92
# File 'lib/faker/default/name.rb', line 90

def neutral_first_name
  fetch('name.neutral_first_name')
end

.prefixString

Produces a random name prefix.

Examples:

Faker::Name.prefix #=> "Mr."

Returns:

  • (String)

Available since:

  • 0.9.0



119
120
121
# File 'lib/faker/default/name.rb', line 119

def prefix
  fetch('name.prefix')
end

.suffixString

Produces a random name suffix.

Examples:

Faker::Name.suffix #=> "IV"

Returns:

  • (String)

Available since:

  • 0.9.0



132
133
134
# File 'lib/faker/default/name.rb', line 132

def suffix
  fetch('name.suffix')
end