Class: WordGenerator::Generator
- Inherits:
-
Object
- Object
- WordGenerator::Generator
- Defined in:
- lib/word_generator/generator.rb
Defined Under Namespace
Classes: WordLengthTooLongError
Instance Attribute Summary collapse
-
#letters ⇒ Object
readonly
Returns the value of attribute letters.
Instance Method Summary collapse
- #generate(word_length) ⇒ Object
-
#initialize(letters) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(letters) ⇒ Generator
Returns a new instance of Generator.
7 8 9 |
# File 'lib/word_generator/generator.rb', line 7 def initialize(letters) @letters = parse_letters(letters) end |
Instance Attribute Details
#letters ⇒ Object (readonly)
Returns the value of attribute letters.
5 6 7 |
# File 'lib/word_generator/generator.rb', line 5 def letters @letters end |
Instance Method Details
#generate(word_length) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/word_generator/generator.rb', line 11 def generate(word_length) max_word_length = WordGenerator.configuration.max_word_length if word_length > max_word_length raise WordLengthTooLongError, "Word length cannot be longer than #{max_word_length}" end possible_words(word_length).select { |word| WordList.contains?(word) } end |