Class: Faker::Lorem
Overview
Based on Perl's Text::Lorem
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.character ⇒ String
Generates single character.
-
.characters(number: 255, min_alpha: 0, min_numeric: 0) ⇒ String
Produces a random string of alphanumeric characters.
-
.multibyte ⇒ String
Generates the emoji.
-
.paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0) ⇒ String
Generates three sentence paragraph.
-
.paragraph_by_chars(number: 256, supplemental: false) ⇒ String
Generates paragraph with 256 characters.
-
.paragraphs(number: 3, supplemental: false) ⇒ Array
Generates three paragraphs.
-
.question(word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Returns the question with 4 words.
-
.questions(number: 3, supplemental: false) ⇒ Array
Generates array of three questions.
-
.sentence(word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Generates sentence.
-
.sentences(number: 3, supplemental: false) ⇒ Array
Generates three sentences.
-
.word ⇒ String
Returs the random word.
-
.words(number: 3, supplemental: false) ⇒ Array
Generates random 3 words.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.character ⇒ String
Generates single character
52 53 54 |
# File 'lib/faker/default/lorem.rb', line 52 def character sample(Types::CHARACTERS) end |
.characters(number: 255, min_alpha: 0, min_numeric: 0) ⇒ String
Produces a random string of alphanumeric characters
72 73 74 |
# File 'lib/faker/default/lorem.rb', line 72 def characters(number: 255, min_alpha: 0, min_numeric: 0) Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric) end |
.multibyte ⇒ String
Generates the emoji
86 87 88 |
# File 'lib/faker/default/lorem.rb', line 86 def multibyte sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8') end |
.paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0) ⇒ String
Generates three sentence paragraph
148 149 150 |
# File 'lib/faker/default/lorem.rb', line 148 def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0) sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental: supplemental).join(locale_space) end |
.paragraph_by_chars(number: 256, supplemental: false) ⇒ String
Generates paragraph with 256 characters
184 185 186 187 188 189 190 |
# File 'lib/faker/default/lorem.rb', line 184 def paragraph_by_chars(number: 256, supplemental: false) paragraph = paragraph(sentence_count: 3, supplemental: supplemental) paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < number "#{paragraph[0...number - 1]}." end |
.paragraphs(number: 3, supplemental: false) ⇒ Array
Generates three paragraphs
166 167 168 |
# File 'lib/faker/default/lorem.rb', line 166 def paragraphs(number: 3, supplemental: false) 1.upto(resolve(number)).collect { paragraph(sentence_count: 3, supplemental: supplemental) } end |
.question(word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Returns the question with 4 words
208 209 210 |
# File 'lib/faker/default/lorem.rb', line 208 def question(word_count: 4, supplemental: false, random_words_to_add: 0) words(number: word_count + rand(random_words_to_add), supplemental: supplemental).join(' ').capitalize + locale_question_mark end |
.questions(number: 3, supplemental: false) ⇒ Array
Generates array of three questions
226 227 228 |
# File 'lib/faker/default/lorem.rb', line 226 def questions(number: 3, supplemental: false) 1.upto(resolve(number)).collect { question(word_count: 3, supplemental: supplemental) } end |
.sentence(word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Generates sentence
106 107 108 |
# File 'lib/faker/default/lorem.rb', line 106 def sentence(word_count: 4, supplemental: false, random_words_to_add: 0) words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(locale_space).capitalize + locale_period end |
.sentences(number: 3, supplemental: false) ⇒ Array
Generates three sentences
124 125 126 |
# File 'lib/faker/default/lorem.rb', line 124 def sentences(number: 3, supplemental: false) 1.upto(resolve(number)).collect { sentence(word_count: 3, supplemental: supplemental) } end |
.word ⇒ String
Returs the random word
15 16 17 |
# File 'lib/faker/default/lorem.rb', line 15 def word sample(translate('faker.lorem.words')) end |
.words(number: 3, supplemental: false) ⇒ Array
Generates random 3 words
33 34 35 36 37 38 39 40 41 |
# File 'lib/faker/default/lorem.rb', line 33 def words(number: 3, supplemental: false) resolved_num = resolve(number) 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 |