Class: RomanNameGenerator::Generator

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

Overview

The Generator class handles the loading and randomizing the json data store containing the roman name stub json. By default you only need to call the initializer, and as soon as it is instantiated, it builds a random roman name based on the gender given.

To get a new name, either initialize a new generator, or call #regenerate

Example:

full_name = RomanNameGenerator::Generator.new("male").result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gender = "male") ⇒ Generator

Generates a random name and assigns it to #result

Parameters:

  • gender (String) (defaults to: "male")

    the name’s gender, ‘male` or `female`, defaults to `male`



24
25
26
27
# File 'lib/roman_name_generator.rb', line 24

def initialize(gender="male")
  self.gender = gender
  generate
end

Instance Attribute Details

#genderObject

Returns the value of attribute gender.



20
21
22
# File 'lib/roman_name_generator.rb', line 20

def gender
  @gender
end

#name_dataObject

Returns the value of attribute name_data.



20
21
22
# File 'lib/roman_name_generator.rb', line 20

def name_data
  @name_data
end

#resultObject

Returns the value of attribute result.



20
21
22
# File 'lib/roman_name_generator.rb', line 20

def result
  @result
end

Instance Method Details

#regenerateObject

Gives another random roman name based on the gender given in the constructor, assigns it to #result, and then returns #result



31
32
33
# File 'lib/roman_name_generator.rb', line 31

def regenerate
  generate
end