Class: Faker::Books::Lovecraft
- Inherits:
-
Faker::Base
- Object
- Faker::Base
- Faker::Books::Lovecraft
- Defined in:
- lib/faker/books/lovecraft.rb
Constant Summary
Constants inherited from Faker::Base
Faker::Base::LLetters, Faker::Base::Letters, Faker::Base::NOT_GIVEN, Faker::Base::Numbers, Faker::Base::ULetters
Class Method Summary collapse
-
.deity ⇒ String
Produces the name of a deity.
- .fhtagn(number: 1) ⇒ String
-
.location ⇒ String
Produces the name of a location.
-
.paragraph(sentence_count: 3, random_sentences_to_add: 3) ⇒ String
Produces a random paragraph.
- .paragraph_by_chars(characters: 256) ⇒ String
-
.paragraphs(number: 3) ⇒ Array<String>
Produces a array of random paragraphs.
-
.sentence(word_count: 4, random_words_to_add: 6, open_compounds_allowed: true) ⇒ String
Produces a random sentence.
-
.sentences(number: 3) ⇒ Array<String>
Produces a array of random sentences.
-
.tome ⇒ String
Produces the name of a tome.
-
.word ⇒ String
Produces a random word.
-
.words(number: 3, spaces_allowed: false) ⇒ Array<String>
Produces a array of random words.
Methods inherited from Faker::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, translate, unique, with_locale
Class Method Details
.deity ⇒ String
Produces the name of a deity
45 46 47 |
# File 'lib/faker/books/lovecraft.rb', line 45 def deity fetch('lovecraft.deity') end |
.fhtagn(number: 1) ⇒ String
32 33 34 |
# File 'lib/faker/books/lovecraft.rb', line 32 def fhtagn(number: 1) Array.new(number) { fetch('lovecraft.fhtagn') }.join('. ') end |
.location ⇒ String
Produces the name of a location
16 17 18 |
# File 'lib/faker/books/lovecraft.rb', line 16 def location fetch('lovecraft.location') end |
.paragraph(sentence_count: 3, random_sentences_to_add: 3) ⇒ String
Produces a random paragraph
192 193 194 |
# File 'lib/faker/books/lovecraft.rb', line 192 def paragraph(sentence_count: 3, random_sentences_to_add: 3) sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ') end |
.paragraph_by_chars(characters: 256) ⇒ String
239 240 241 242 243 244 245 |
# File 'lib/faker/books/lovecraft.rb', line 239 def paragraph_by_chars(characters: 256) paragraph = paragraph(sentence_count: 3) paragraph += " #{paragraph(sentence_count: 3)}" while paragraph.length < characters "#{paragraph[0...characters - 1]}." end |
.paragraphs(number: 3) ⇒ Array<String>
Produces a array of random paragraphs
218 219 220 221 222 223 224 |
# File 'lib/faker/books/lovecraft.rb', line 218 def paragraphs(number: 3) [].tap do |paragraphs| 1.upto(resolve(number)) do paragraphs << paragraph(sentence_count: 3) end end end |
.sentence(word_count: 4, random_words_to_add: 6, open_compounds_allowed: true) ⇒ String
Produces a random sentence
85 86 87 |
# File 'lib/faker/books/lovecraft.rb', line 85 def sentence(word_count: 4, random_words_to_add: 6, open_compounds_allowed: true) "#{words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: open_compounds_allowed).join(' ').capitalize}." end |
.sentences(number: 3) ⇒ Array<String>
Produces a array of random sentences
165 166 167 168 169 170 171 |
# File 'lib/faker/books/lovecraft.rb', line 165 def sentences(number: 3) [].tap do |sentences| 1.upto(resolve(number)) do sentences << sentence(word_count: 3) end end end |
.tome ⇒ String
Produces the name of a tome
58 59 60 |
# File 'lib/faker/books/lovecraft.rb', line 58 def tome fetch('lovecraft.tome') end |
.word ⇒ String
Produces a random word
98 99 100 101 |
# File 'lib/faker/books/lovecraft.rb', line 98 def word random_word = sample(translate('faker.lovecraft.words')) random_word =~ /\s/ ? word : random_word end |
.words(number: 3, spaces_allowed: false) ⇒ Array<String>
Produces a array of random words
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/faker/books/lovecraft.rb', line 132 def words(number: 3, spaces_allowed: false) resolved_num = resolve(number) word_list = translate('faker.lovecraft.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 |