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(sentence_count: 3, supplemental: false, random_sentences_to_add: 3) ⇒ String
Produces a random hipster paragraph.
-
.paragraph_by_chars(characters: 256, supplemental: false) ⇒ String
Produces a random hipster paragraph by characters.
-
.paragraphs(number: 3, supplemental: false) ⇒ Array<String>
Produces random hipster paragraphs.
-
.sentence(word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true) ⇒ String
Produces a random hipster sentence.
-
.sentences(number: 3, supplemental: false) ⇒ Array<String>
Produces random hipster sentences.
-
.word ⇒ String
Produces a random hipster word.
-
.words(number: 3, supplemental: false, spaces_allowed: false) ⇒ Array<String>
Produces a random hipster word.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 3) ⇒ String
Produces a random hipster paragraph.
108 109 110 |
# File 'lib/faker/default/hipster.rb', line 108 def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 3) sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ') end |
.paragraph_by_chars(characters: 256, supplemental: false) ⇒ String
Produces a random hipster paragraph by characters.
145 146 147 148 149 150 151 |
# File 'lib/faker/default/hipster.rb', line 145 def paragraph_by_chars(characters: 256, supplemental: false) paragraph = paragraph(sentence_count: 3, supplemental: supplemental) paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters "#{paragraph[0...characters - 1]}." end |
.paragraphs(number: 3, supplemental: false) ⇒ Array<String>
Produces random hipster paragraphs.
125 126 127 128 129 130 131 |
# File 'lib/faker/default/hipster.rb', line 125 def paragraphs(number: 3, supplemental: false) [].tap do |paragraphs| 1.upto(resolve(number)) do paragraphs << paragraph(sentence_count: 3, supplemental: supplemental) end end end |
.sentence(word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true) ⇒ String
Produces a random hipster sentence.
67 68 69 |
# File 'lib/faker/default/hipster.rb', line 67 def sentence(word_count: 4, supplemental: false, random_words_to_add: 6, open_compounds_allowed: true) "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: open_compounds_allowed).join(' ').capitalize}." end |
.sentences(number: 3, supplemental: false) ⇒ Array<String>
Produces random hipster sentences.
84 85 86 87 88 89 90 |
# File 'lib/faker/default/hipster.rb', line 84 def sentences(number: 3, supplemental: false) [].tap do |sentences| 1.upto(resolve(number)) do sentences << sentence(word_count: 3, supplemental: supplemental) end end end |
.word ⇒ String
Produces a random hipster word.
15 16 17 18 |
# File 'lib/faker/default/hipster.rb', line 15 def word random_word = sample(translate('faker.hipster.words')) random_word =~ /\s/ ? word : random_word end |
.words(number: 3, supplemental: false, spaces_allowed: false) ⇒ Array<String>
Produces a random hipster word.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/faker/default/hipster.rb', line 35 def words(number: 3, supplemental: false, spaces_allowed: false) resolved_num = resolve(number) word_list = ( translate('faker.hipster.words') + (supplemental ? translate('faker.lorem.words') : []) ) word_list *= ((resolved_num / word_list.length) + 1) words = sample(word_list, resolved_num) return words if spaces_allowed words.each_with_index { |w, i| words[i] = word if w =~ /\s/ } end |