Sha256: 1f381565cb31b5d872ed535851142590fe3b352fbd79013ce4a88f9eff105b4a
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
module Faker # Based on Perl's Text::Lorem class Lorem < Base 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 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 def self.sentence(word_count = 4, supplemental = false) words(randomize(word_count) + rand(6), supplemental).join(' ').capitalize + '.' end def self.sentences(sentence_count = 3, supplemental = false) [].tap do |sentences| 1.upto(randomize(sentence_count)) do sentences << sentence(3, supplemental) end end end def self.paragraph(sentence_count = 3, supplemental = false) sentences(randomize(sentence_count) + rand(3), supplemental).join(' ') end def self.paragraphs(paragraph_count = 3, supplemental = false) [].tap do |paragraphs| 1.upto(randomize(paragraph_count)) do paragraphs << paragraph(3, supplemental) end end end protected def self.randomize(value) case value when Range rand(value.max - value.min) + value.min else value end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
faker19-1.0.5 | lib/faker/lorem.rb |
faker19-1.0.4 | lib/faker/lorem.rb |