Class: Faker::Hipster
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.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: 3) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- .paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false) ⇒ Object
- .paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Object
-
.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: 6) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- .sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Object
- .word ⇒ Object
-
.words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false) ⇒ Object
rubocop:disable Metrics/ParameterLists.
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
.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: 3) ⇒ Object
rubocop:disable Metrics/ParameterLists
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/faker/default/hipster.rb', line 59 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: 3) # rubocop:enable Metrics/ParameterLists 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).to_i, supplemental: supplemental).join(' ') end |
.paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/faker/default/hipster.rb', line 83 def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false) warn_for_deprecated_arguments do |keywords| keywords << :characters if legacy_characters != 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 < characters paragraph[0...characters - 1] + '.' end |
.paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/faker/default/hipster.rb', line 70 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 keywords << :supplemental if legacy_supplemental != NOT_GIVEN end [].tap do |paragraphs| 1.upto(resolve(number)) do paragraphs << paragraph(sentence_count: 3, supplemental: supplemental) end end 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: 6) ⇒ Object
rubocop:disable Metrics/ParameterLists
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/faker/default/hipster.rb', line 34 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: 6) # rubocop:enable Metrics/ParameterLists 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).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.' end |
.sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/faker/default/hipster.rb', line 45 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 [].tap do |sentences| 1.upto(resolve(number)) do sentences << sentence(word_count: 3, supplemental: supplemental) end end end |
.word ⇒ Object
6 7 8 9 |
# File 'lib/faker/default/hipster.rb', line 6 def word random_word = sample(translate('faker.hipster.words')) random_word =~ /\s/ ? word : random_word end |
.words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false) ⇒ Object
rubocop:disable Metrics/ParameterLists
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/faker/default/hipster.rb', line 12 def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false) # rubocop:enable Metrics/ParameterLists warn_for_deprecated_arguments do |keywords| keywords << :number if legacy_number != NOT_GIVEN keywords << :supplemental if legacy_supplemental != NOT_GIVEN keywords << :spaces_allowed if legacy_spaces_allowed != NOT_GIVEN end resolved_num = resolve(number) word_list = ( translate('faker.hipster.words') + (supplemental ? translate('faker.lorem.words') : []) ) word_list *= ((resolved_num / word_list.length) + 1) return shuffle(word_list)[0, resolved_num] if spaces_allowed words = shuffle(word_list)[0, resolved_num] words.each_with_index { |w, i| words[i] = word if w =~ /\s/ } end |