Class: Faker::Lorem

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

Overview

Based on Perl’s Text::Lorem

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, letterify, numerify

Class Method Details

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



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

def self.paragraph(sentence_count = 3, supplemental = false)
  sentences(randomize(sentence_count) + rand(3), supplemental).join(' ')
end

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



39
40
41
42
43
44
45
# File 'lib/faker/lorem.rb', line 39

def self.paragraphs(paragraph_count = 3, supplemental = false)
  [].tap do |paragraphs|
    1.upto(randomize(paragraph_count)) do
      paragraphs << paragraph(3, supplemental)
    end
  end
end

.sentence(word_count = 4, supplemental = false) ⇒ Object



23
24
25
# File 'lib/faker/lorem.rb', line 23

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

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



27
28
29
30
31
32
33
# File 'lib/faker/lorem.rb', line 27

def self.sentences(sentence_count = 3, supplemental = false)
  [].tap do |sentences|
    1.upto(randomize(sentence_count)) do
      sentences << sentence(3, supplemental)
    end
  end
end

.shuffleObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/faker/lorem.rb', line 4

def self.shuffle
  lorem = [
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod",
    "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,",
    "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo",
    "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse",
    "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat",
    "non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
  ]

  lorem.shuffle.join(' ')
end

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



17
18
19
20
21
# File 'lib/faker/lorem.rb', line 17

def self.words(num = 3, supplemental = false)
  wordlist = I18n.translate('faker.lorem.words')
  wordlist += I18n.translate('faker.lorem.supplemental') if supplemental
  wordlist.shuffle[0, randomize(num)]
end