word_salad 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 684b5abb322dfe9d2cacb4d9aa383f1f14a6e287c98ef8bc6dcb86f6b5b65a5b
4
- data.tar.gz: e9b55115b7f66b36d740bc4f02d771d7e6c52f5d8cab09fd31fee112caf2f125
3
+ metadata.gz: 4cf04e92ce6207b4ff8f9314766652e4b4225b0cde9e422369045b8df9d0e708
4
+ data.tar.gz: fe5bc278afe8bc834f302e6fc19e056e935cdf7213ddb078669a74edd56d3e2e
5
5
  SHA512:
6
- metadata.gz: 407ac779a10724569d94c3d527f59d54fa4febb162b0a165b840b0b961f67ba621cede50f514aa6291044d9dc513c61b27d647cd8e2cc7e723e5440b588bd692
7
- data.tar.gz: 7ec4aecdb6f801fb255b318146994c8021b8d8a4990b1cb9048bffd27b229887733d57bcc21f6e5cb7172be9740758535ac859e542e8e7cd479de515f8a7c199
6
+ metadata.gz: f82a5f65cf626acb53f5f56ab73963212fafcf526826c69d583b9773894ced461505106ee5a2adc7227c0f6b8946425db346199f19798f55ff60677628947922
7
+ data.tar.gz: 6ff1b6ab2ee0df6e57ac9326c182670aa06314d2f226c7380f30ab78d4a299ba5c0550a19167ef572826516092193bc219db336c7bb93426aa78efc761047ecc
@@ -4,48 +4,37 @@
4
4
  raise "#{meth} is already defined in Integer class" if Integer.method_defined?(meth)
5
5
  end
6
6
 
7
- # extends the build in Integer class
7
+ # extends the Integer class
8
8
  class Integer
9
- # Returns 1 random word
10
- def word
11
- 1.words.first
12
- end
9
+ # Returns 1 random word from the dictionary
10
+ def word = WordSalad.words.sample
11
+ # Returns an array of +num+ random words from the dictionary.
12
+ def words = WordSalad.words.sample(self)
13
13
 
14
14
  # Returns 1 sentence of random words about +size+ long
15
- def sentence(size = 10)
16
- 1.sentences(size).first
17
- end
18
-
19
- # Returns 1 paragraph of +psize+ sentences,
20
- # each about +ssize+ words long
21
- def paragraph(psize = 5, ssize = 10)
22
- 1.paragraphs(psize, ssize).first
15
+ def sentence(size = 10, variance: true)
16
+ words = if variance
17
+ variance = rand((size / 4) + 1)
18
+ variance = 0 - variance if rand(2).zero? # plus or minus
19
+ (size + variance).words
20
+ else
21
+ size.words
22
+ end
23
+ "#{words.join(' ').capitalize}."
23
24
  end
24
25
 
25
- # Returns +num+ random words from the dictionary.
26
- def words
27
- WordSalad.dictionary
28
- (1..self).to_a.map do |_x|
29
- WordSalad.words[rand(WordSalad.size)].strip
30
- end
26
+ # Returns an array of +num+ sentences of random words about +size+ long
27
+ def sentences(size = 10, variance: true)
28
+ times.collect { sentence(size, variance: variance) }
31
29
  end
32
30
 
33
- # Returns +num+ sentences of random words about +size+ long
34
- def sentences(size = 10)
35
- (1..self).to_a.map do |_x|
36
- variance = rand((size / 3) + 1)
37
- variance = 0 - variance if rand(2).zero? # plus or minus
38
- w = (size + variance).words
39
- w[0].capitalize!
40
- "#{w.join(' ')}."
41
- end
31
+ # Returns 1 paragraph of +psize+ sentences, each about +ssize+ words long
32
+ def paragraph(psize = 5, ssize = 10, variance: true)
33
+ psize.sentences(ssize, variance: variance).join(' ')
42
34
  end
43
35
 
44
- # Returns +num+ paragraphs of +psize+ sentences,
45
- # each about +ssize+ words long
46
- def paragraphs(psize = 5, ssize = 10)
47
- (1..self).to_a.map do |_x|
48
- psize.sentences(ssize).join(' ')
49
- end
36
+ # Returns +num+ paragraphs of +psize+ sentences about +ssize+ words long
37
+ def paragraphs(psize = 5, ssize = 10, variance: true)
38
+ times.collect { paragraph(psize, ssize, variance: variance) }
50
39
  end
51
40
  end