Class: UniqueNamesGenerator::Generator

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

Overview

UniqueNamesGenerator::Generator

This class generates unique names based on specified dictionaries and configuration options. It allows for customizable name generation with various styles, separators, and creativity levels.

Instance Method Summary collapse

Constructor Details

#initialize(dictionaries, separator: '_', style: :lowercase, creativity: 0) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
# File 'lib/unique_names_generator.rb', line 23

def initialize(dictionaries, separator: '_', style: :lowercase, creativity: 0)
  @dictionaries = dictionaries
  @separator = separator
  @style = style
  @creativity = creativity

  # Will raise error if any specified dictionary is invalid
  dictionaries.map { |dictionary| word_list(dictionary) }
  raise ArgumentError, 'Outside creativity range. Must be between 0 and 10.' if outside_creativity_bounds?
end

Instance Method Details

#generate(seed: nil) ⇒ Object



34
35
36
37
# File 'lib/unique_names_generator.rb', line 34

def generate(seed: nil)
  @seed = seed
  generate_name(@dictionaries)
end