class Namelab::WordGenerator
The word generator class.
Constants
- LengthFilter
Attributes
word[R]
Public Instance Methods
chars_left()
click to toggle source
Calculates how many chars are left to generate.
# File lib/namelab/word_generator.rb, line 37 def chars_left @target_length - word.length end
generate()
click to toggle source
Generates word and cleanups instance variables.
# File lib/namelab/word_generator.rb, line 24 def generate while chars_left > 0 word << sample_syllable normalize! if normalize end return @word.capitalize ensure cleanup! end
Also aliased as: call
sample_syllable()
click to toggle source
Fetches random syllable.
# File lib/namelab/word_generator.rb, line 44 def sample_syllable filter = LengthFilter[:<=, chars_left.next] if chars_left <= 3 Registry['syls.sample'][filter].to_s end
Private Instance Methods
cleanup!()
click to toggle source
# File lib/namelab/word_generator.rb, line 56 def cleanup! remove_instance_variable(:@word) end
normalize!()
click to toggle source
# File lib/namelab/word_generator.rb, line 51 def normalize! @word.sub!(/([^aeiouy]{2})[^aeiouy]/, '\1') @word = @word[0, @target_length] end