Class: Faker::Lorem

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/lorem.rb

Overview

Based on Perl's Text::Lorem

Constant Summary collapse

CHARACTERS =
('0'..'9').to_a + ('a'..'z').to_a

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, sample, shuffle, translate, unique, with_locale

Class Method Details

.characterObject


21
22
23
# File 'lib/faker/lorem.rb', line 21

def character
  sample(CHARACTERS)
end

.characters(char_count = 255) ⇒ Object


25
26
27
28
29
# 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

.paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3) ⇒ Object


39
40
41
# File 'lib/faker/lorem.rb', line 39

def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
  sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(' ')
end

.paragraphs(paragraph_count = 3, supplemental = false) ⇒ Object


43
44
45
# File 'lib/faker/lorem.rb', line 43

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 = 6) ⇒ Object


47
48
49
# File 'lib/faker/lorem.rb', line 47

def question(word_count = 4, supplemental = false, random_words_to_add = 6)
  words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + '?'
end

.questions(question_count = 3, supplemental = false) ⇒ Object


51
52
53
# File 'lib/faker/lorem.rb', line 51

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 = 6) ⇒ Object


31
32
33
# File 'lib/faker/lorem.rb', line 31

def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
  words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + '.'
end

.sentences(sentence_count = 3, supplemental = false) ⇒ Object


35
36
37
# File 'lib/faker/lorem.rb', line 35

def sentences(sentence_count = 3, supplemental = false)
  1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) }
end

.wordObject


7
8
9
# File 'lib/faker/lorem.rb', line 7

def word
  sample(translate('faker.lorem.words'))
end

.words(num = 3, supplemental = false) ⇒ Object


11
12
13
14
15
16
17
18
19
# 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 = word_list * ((resolved_num / word_list.length) + 1)
  shuffle(word_list)[0, resolved_num]
end