Module: LaoWaiHua

Defined in:
lib/lao_wai_hua.rb,
lib/lao_wai_hua/railtie.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

WORDS =
%w(
        
        
        
        
        
        
        
      湿 
)
PUNCTUATION =
%w(    )
WORDS_WITHOUT_PUNCTUATION =
WORDS.select{|word| !PUNCTUATION.include?(word)}

Class Method Summary collapse

Class Method Details

.generate(length = WORDS.length) ⇒ Object

return a string of length taken from the provided tongue twister defaults to the full length of the text



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

def generate(length=WORDS.length)
 words = []
 while words.length < length
  words += WORDS[0, length]
 end
 words.join("")
end

.random(length) ⇒ Object

return a string or random words of the provided length



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lao_wai_hua.rb', line 37

def random(length)
 words = []
  next_punctuation = nil

	1.upto(length) do
	  next_punctuation ||= rand(3)+2
	  if next_punctuation == 0
	    next_punctuation = nil
	    words << random_punctuation
	  else
	    next_punctuation -= 1
	    words << random_word
	  end
	end
	words.join("")
end

.random_wordObject

return a random word (excluding punctuation) from our text



32
33
34
# File 'lib/lao_wai_hua.rb', line 32

def random_word()
 WORDS_WITHOUT_PUNCTUATION[rand(WORDS_WITHOUT_PUNCTUATION.length)]
end