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(legacy_number = NOT_GIVEN, number: 255, min_alpha: 0, min_numeric: 0) ⇒ String
Produces a random string of alphanumeric characters.
-
.multibyte ⇒ String
Generates the emoji.
-
.paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 0) ⇒ String
Generates three sentence paragraph.
-
.paragraph_by_chars(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 256, supplemental: false) ⇒ String
Generates paragraph with 256 characters.
-
.paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates three paragraphs.
-
.question(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Returns the question with 4 words.
-
.questions(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates array of three questions.
-
.sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Generates sentence.
-
.sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates three sentences.
-
.word ⇒ String
Returs the random word.
-
.words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, 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
57 58 59 |
# File 'lib/faker/default/lorem.rb', line 57 def character sample(Types::CHARACTERS) end |
.characters(legacy_number = NOT_GIVEN, number: 255, min_alpha: 0, min_numeric: 0) ⇒ String
Produces a random string of alphanumeric characters
77 78 79 80 81 82 83 |
# File 'lib/faker/default/lorem.rb', line 77 def characters(legacy_number = NOT_GIVEN, number: 255, min_alpha: 0, min_numeric: 0) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN end Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric) end |
.multibyte ⇒ String
Generates the emoji
95 96 97 |
# File 'lib/faker/default/lorem.rb', line 95 def multibyte sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8') end |
.paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 0) ⇒ String
Generates three sentence paragraph
172 173 174 175 176 177 178 179 180 |
# File 'lib/faker/default/lorem.rb', line 172 def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 0) warn_for_deprecated_arguments do |keywords| keywords << :sentence_count if legacy_sentence_count != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN keywords << :random_sentences_to_add if legacy_random_sentences_to_add != NOT_GIVEN end sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental: supplemental).join(locale_space) end |
.paragraph_by_chars(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 256, supplemental: false) ⇒ String
Generates paragraph with 256 characters
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/faker/default/lorem.rb', line 222 def paragraph_by_chars(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 256, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN end paragraph = paragraph(sentence_count: 3, supplemental: supplemental) paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < number "#{paragraph[0...number - 1]}." end |
.paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates three paragraphs
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/faker/default/lorem.rb', line 197 def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN end warn_for_deprecated_arguments do |keywords| keywords << :supplemental if legacy_supplemental != NOT_GIVEN end 1.upto(resolve(number)).collect { paragraph(sentence_count: 3, supplemental: supplemental) } end |
.question(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Returns the question with 4 words
253 254 255 256 257 258 259 260 261 |
# File 'lib/faker/default/lorem.rb', line 253 def question(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) warn_for_deprecated_arguments do |keywords| keywords << :word_count if legacy_word_count != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN end words(number: word_count + rand(random_words_to_add), supplemental: supplemental).join(' ').capitalize + locale_question_mark end |
.questions(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates array of three questions
278 279 280 281 282 283 284 285 |
# File 'lib/faker/default/lorem.rb', line 278 def questions(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN end 1.upto(resolve(number)).collect { question(word_count: 3, supplemental: supplemental) } end |
.sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) ⇒ String
Generates sentence
116 117 118 119 120 121 122 123 124 |
# File 'lib/faker/default/lorem.rb', line 116 def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0) warn_for_deprecated_arguments do |keywords| keywords << :word_count if legacy_word_count != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN end words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(locale_space).capitalize + locale_period end |
.sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates three sentences
141 142 143 144 145 146 147 148 |
# File 'lib/faker/default/lorem.rb', line 141 def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN end 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(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Array
Generates random 3 words
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/faker/default/lorem.rb', line 33 def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN end 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 |