Module: RandomWordGenerator

Defined in:
lib/random_word_generator/version.rb,
lib/random_word_generator.rb

Overview

:nodoc:

Defined Under Namespace

Modules: VERSION

Class Method Summary collapse

Class Method Details

.composed(words = 2, length = 14, separator = ' ') ⇒ Object



32
33
34
35
36
37
# File 'lib/random_word_generator.rb', line 32

def self.composed(words=2, length=14, separator=' ')
  @length = length - (separator.size * (words - 1))
  minimum_word_length = 4
  lengths = Randomizer.random_lengths_matching_sum(words, @length, 4)
  lengths.map{ |wl| @db.find_word_of_length(wl) }.join(%{#{separator}})
end

.of_length(length = 8) ⇒ Object

Returns a random word of a define length. If no word is found in the dictionary, a random string is generated



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

def self.of_length(length=8)
  word = @db.find_word_of_length(length)
  if word.nil? 
    Randomizer.random_string(length) 
  else
    word
  end
end

.wordObject

Returns a random word



17
18
19
# File 'lib/random_word_generator.rb', line 17

def self.word
  @db.find_random_word
end