Module: RandomNameGenerator

Defined in:
lib/random_name_generator.rb,
lib/random_name_generator/version.rb,
lib/random_name_generator/syllable.rb

Overview

RandomNameGenerator:

Examples

rng = RandomNameGenerator::Generator.new(RandomNameGenerator::GOBLIN)
puts rng.compose(3)

By default RandomNameGenerator uses the Fantasy syllable file and creates a name with between 2 and 5 syllables.

rng = RandomNameGenerator::Generator.new
puts rng.compose

:reek:TooManyConstants :reek:TooManyInstanceVariables :reek:TooManyStatements

Defined Under Namespace

Classes: Generator, Syllable

Constant Summary collapse

ELVEN =
File.new("#{dirname}/languages/elven.txt")
FANTASY =
File.new("#{dirname}/languages/fantasy.txt")
GOBLIN =
File.new("#{dirname}/languages/goblin.txt")
ROMAN =
File.new("#{dirname}/languages/roman.txt")
ELVEN_RU =
File.new("#{dirname}/languages/elven-ru.txt")
FANTASY_RU =
File.new("#{dirname}/languages/fantasy-ru.txt")
GOBLIN_RU =
File.new("#{dirname}/languages/goblin-ru.txt")
ROMAN_RU =
File.new("#{dirname}/languages/roman-ru.txt")
CURSE =

Experimental

File.new("#{dirname}/languages/experimental/curse.txt")
VERSION =
"3.0.0"

Class Method Summary collapse

Class Method Details

.flip_modeObject

Static factory method that instantiates a RandomNameGenerator in a random language.



38
39
40
41
42
43
44
# File 'lib/random_name_generator.rb', line 38

def self.flip_mode
  langs = [RandomNameGenerator::FANTASY,
           RandomNameGenerator::ELVEN,
           RandomNameGenerator::GOBLIN,
           RandomNameGenerator::ROMAN]
  Generator.new(langs.sample)
end

.flip_mode_cyrillicObject

Static factory method that instantiates a RandomNameGenerator in a random Cyrillic based language.



48
49
50
51
52
53
54
# File 'lib/random_name_generator.rb', line 48

def self.flip_mode_cyrillic
  langs = [RandomNameGenerator::FANTASY_RU,
           RandomNameGenerator::ELVEN_RU,
           RandomNameGenerator::GOBLIN_RU,
           RandomNameGenerator::ROMAN_RU]
  Generator.new(langs.sample)
end

.new(language = RandomNameGenerator::FANTASY, random: Random.new) ⇒ Object

Static factory method for the Generator class.



61
62
63
# File 'lib/random_name_generator.rb', line 61

def self.new(language = RandomNameGenerator::FANTASY, random: Random.new)
  Generator.new(language, random: random)
end

.pick_number_of_syllables(random: Random.new) ⇒ Object



56
57
58
# File 'lib/random_name_generator.rb', line 56

def self.pick_number_of_syllables(random: Random.new)
  [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5].sample(random: random)
end