Sha256: 0161f1d6eab0842996b86163c27c6f72c3969e634644d832b717e2f203a4d86f
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
module Faker # Based on Perl's Text::Lorem class Lorem < Base 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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
faker19-1.0.3 | lib/faker/lorem.rb |
faker19-1.0.2 | lib/faker/lorem.rb |
faker19-1.0.1 | lib/faker/lorem.rb |
faker19-1.0.0 | lib/faker/lorem.rb |