class Faker::Lorem
Based on Perl's Text::Lorem
Constants
- CHARACTERS
Public Class Methods
character()
click to toggle source
# File lib/faker/lorem.rb, line 21 def character sample(CHARACTERS) end
characters(char_count = 255)
click to toggle source
# File lib/faker/lorem.rb, line 25 def characters(char_count = 255) char_count = resolve(char_count) return '' if char_count.to_i < 1 Array.new(char_count) { sample(CHARACTERS) }.join end
multibyte()
click to toggle source
# File lib/faker/lorem.rb, line 31 def multibyte sample('faker.multibyte') end
paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0)
click to toggle source
# File lib/faker/lorem.rb, line 43 def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0) sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space) end
paragraph_by_chars(chars = 256, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 51 def paragraph_by_chars(chars = 256, supplemental = false) paragraph = paragraph(3, supplemental) paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars paragraph[0...chars - 1] + '.' end
paragraphs(paragraph_count = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 47 def paragraphs(paragraph_count = 3, supplemental = false) 1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) } end
question(word_count = 4, supplemental = false, random_words_to_add = 0)
click to toggle source
# File lib/faker/lorem.rb, line 59 def question(word_count = 4, supplemental = false, random_words_to_add = 0) words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark end
questions(question_count = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 63 def questions(question_count = 3, supplemental = false) 1.upto(resolve(question_count)).collect { question(3, supplemental) } end
sentence(word_count = 4, supplemental = false, random_words_to_add = 0)
click to toggle source
# File lib/faker/lorem.rb, line 35 def sentence(word_count = 4, supplemental = false, random_words_to_add = 0) words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period end
sentences(sentence_count = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 39 def sentences(sentence_count = 3, supplemental = false) 1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) } end
word()
click to toggle source
# File lib/faker/lorem.rb, line 7 def word sample(translate('faker.lorem.words')) end
words(num = 3, supplemental = false)
click to toggle source
# File lib/faker/lorem.rb, line 11 def words(num = 3, supplemental = false) resolved_num = resolve(num) word_list = ( translate('faker.lorem.words') + (supplemental ? translate('faker.lorem.supplemental') : []) ) word_list *= ((resolved_num / word_list.length) + 1) shuffle(word_list)[0, resolved_num] end
Private Class Methods
locale_period()
click to toggle source
# File lib/faker/lorem.rb, line 69 def locale_period translate('faker.lorem.punctuation.period') || '.' end
locale_question_mark()
click to toggle source
# File lib/faker/lorem.rb, line 77 def locale_question_mark translate('faker.lorem.punctuation.question_mark') || '?' end
locale_space()
click to toggle source
# File lib/faker/lorem.rb, line 73 def locale_space translate('faker.lorem.punctuation.space') || ' ' end
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 83 def resolve(value) case value when Array then sample(value) when Range then rand value else value end end