class Faker::Lorem
Based on Perl's Text::Lorem
Public Class Methods
character()
click to toggle source
# File lib/faker/lorem.rb, line 19 def character characters(1) end
characters(char_count = 255)
click to toggle source
# File lib/faker/lorem.rb, line 23 def characters(char_count = 255) return '' if char_count.respond_to?(:to_i) && char_count.to_i < 1 char_count = resolve(char_count) rand(36**char_count).to_s(36).rjust(char_count, '0').chars.to_a.shuffle.join end
paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
click to toggle source
# File lib/faker/lorem.rb, line 41 def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental).join(' ') end
paragraphs(paragraph_count = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 45 def paragraphs(paragraph_count = 3, supplemental = false) [].tap do |paragraphs| 1.upto(resolve(paragraph_count)) do paragraphs << paragraph(3, supplemental) end end end
sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
click to toggle source
# File lib/faker/lorem.rb, line 29 def sentence(word_count = 4, supplemental = false, random_words_to_add = 6) words(word_count + rand(random_words_to_add.to_i).to_i, supplemental).join(' ').capitalize + '.' end
sentences(sentence_count = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 33 def sentences(sentence_count = 3, supplemental = false) [].tap do |sentences| 1.upto(resolve(sentence_count)) do sentences << sentence(3, supplemental) end end end
word()
click to toggle source
# File lib/faker/lorem.rb, line 5 def word translate('faker.lorem.words').sample end
words(num = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 9 def words(num = 3, supplemental = false) resolved_num = resolve(num) word_list = ( translate('faker.lorem.words') + (supplemental ? translate('faker.lorem.supplemental') : []) ) word_list = word_list * ((resolved_num / word_list.length) + 1) word_list.shuffle[0, resolved_num] end
Private Class Methods
resolve(value)
click to toggle source
If an array or range is passed, a random value will be selected. All other values are simply returned.
# File lib/faker/lorem.rb, line 57 def resolve(value) case value when Array then value[rand(value.size)] when Range then rand((value.last+1) - value.first) + value.first else value end end