Class: Integer

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

Overview

extends the Integer class

Instance Method Summary collapse

Instance Method Details

#paragraph(psize = 5, ssize = 10, variance: true) ⇒ Object

Returns 1 paragraph of psize sentences, each about ssize words long



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

def paragraph(psize = 5, ssize = 10, variance: true)
  psize.sentences(ssize, variance: variance).join(' ')
end

#paragraphs(psize = 5, ssize = 10, variance: true) ⇒ Object

Returns num paragraphs of psize sentences about ssize words long



37
38
39
# File 'lib/word_salad/core_ext.rb', line 37

def paragraphs(psize = 5, ssize = 10, variance: true)
  times.collect { paragraph(psize, ssize, variance: variance) }
end

#sentence(size = 10, variance: true) ⇒ Object

Returns 1 sentence of random words about size long



15
16
17
18
19
20
21
22
23
24
# File 'lib/word_salad/core_ext.rb', line 15

def sentence(size = 10, variance: true)
  words = if variance
            variance = rand((size / 4) + 1)
            variance = 0 - variance if rand(2).zero? # plus or minus
            (size + variance).words
          else
            size.words
          end
  "#{words.join(' ').capitalize}."
end

#sentences(size = 10, variance: true) ⇒ Object

Returns an array of num sentences of random words about size long



27
28
29
# File 'lib/word_salad/core_ext.rb', line 27

def sentences(size = 10, variance: true)
  times.collect { sentence(size, variance: variance) }
end

#wordObject

Returns 1 random word from the dictionary



10
11
# File 'lib/word_salad/core_ext.rb', line 10

def word = WordSalad.words.sample
# Returns an array of +num+ random words from the dictionary.

#wordsObject

Returns an array of num random words from the dictionary.



12
# File 'lib/word_salad/core_ext.rb', line 12

def words = WordSalad.words.sample(self)