lib/ripsum/ripsum_helper.rb in ripsum-0.1.2 vs lib/ripsum/ripsum_helper.rb in ripsum-0.1.3
- old
+ new
@@ -1,20 +1,24 @@
module Ripsum
- def ripsum(standard, variance)
+ def ripsum(standard, variance=0)
lorem = library
text = []
- min = standard - (standard * variance)
- max = standard + (standard * variance)
lorem_array = lorem.split(' ').shuffle
while standard > lorem_array.length
lorem_array.concat(lorem_array.shuffle)
end
- random_number = rand(min..max).floor
+ if variance != 0
+ min = standard - (standard * variance)
+ max = standard + (standard * variance)
+ word_count = rand(min..max).floor
+ else
+ word_count = standard
+ end
- 1..random_number.times do |i|
+ 1..word_count.times do |i|
if i == 0
text << lorem_array[i].capitalize
else
text << lorem_array[i]
end