Class: Faussaire::Name

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

Constant Summary collapse

DATA_PATH =
File.expand_path('../../locale/fr.yml', __dir__)

Class Method Summary collapse

Class Method Details

.family_nameString

Produces a random family name.

Examples:

Faussaire::Name.family_name #=> "Dupont"

Returns:

  • (String)


49
50
51
52
# File 'lib/faussaire/name.rb', line 49

def family_name
  key = 'fr.faussaire.name.family_name'
  fetch(key)
end

.female_first_nameString

Produces a random female first name.

Examples:

Faussaire::Name.female_first_name #=> "Marie"

Returns:

  • (String)


23
24
25
26
# File 'lib/faussaire/name.rb', line 23

def female_first_name
  key = 'fr.faussaire.name.female_first_name'
  fetch(key)
end

.initialize_dataObject

Initializes the data from the YAML file.



11
12
13
# File 'lib/faussaire/name.rb', line 11

def initialize_data
  @data = YAML.load_file(DATA_PATH)
end

.male_first_nameString

Produces a random male first name.

Examples:

Faussaire::Name.male_first_name #=> "Jean"

Returns:

  • (String)


36
37
38
39
# File 'lib/faussaire/name.rb', line 36

def male_first_name
  key = 'fr.faussaire.name.male_first_name'
  fetch(key)
end

.nameString

Generates a full name by combining a random first name (either male or female) with a family name.

Examples:

Faussaire::Name.name #=> "Marie Dupont"

Returns:

  • (String)


62
63
64
65
# File 'lib/faussaire/name.rb', line 62

def name
  first_name = [female_first_name, male_first_name].sample
  [first_name, family_name].join(' ')
end