Class: Fixnum

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

Instance Method Summary collapse

Instance Method Details

#paragraphs(psize = 5, ssize = 10) ⇒ Object Also known as: paragraph

Returns num paragraphs of around psize sentences, each around ssize number of words



34
35
36
37
38
# File 'lib/word_salad/core_ext.rb', line 34

def paragraphs(psize=5, ssize=10)
  (1..self).to_a.map do |x|
    psize.sentences.join(' ')
  end
end

#sentences(size = 10) ⇒ Object Also known as: sentence

Returns num sentences of random words around size number of words.



21
22
23
24
25
26
27
28
# File 'lib/word_salad/core_ext.rb', line 21

def sentences(size=10)
  variance = size / 5
  (1..self).to_a.map do |x|
    w = (size + (rand(variance) - variance / 2)).words
    w[0].capitalize!
    w.join(' ') + '.'
  end
end

#wordsObject Also known as: word

Returns num random words from the dictionary.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/word_salad/core_ext.rb', line 4

def words
  dict = WordSalad.dictionary
  (1..self).to_a.map do |x|
    dict.seek(rand(WordSalad.size - 1000))
    b = dict.readchar
    while b != 10
      b = dict.readchar
    end

    dict.readline.strip
  end
end