Class: Faker::Books::Lovecraft

Inherits:
Faker::Base show all
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

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, shuffle!, translate, unique, with_locale

Class Method Details

.deityString

Produces the name of a deity

Examples:

Faker::Books::Lovecraft.deity #=> "Shub-Niggurath"

Returns:

  • (String)

Available since:

  • 1.9.3



45
46
47
# File 'lib/faker/books/lovecraft.rb', line 45

def deity
  fetch('lovecraft.deity')
end

.fhtagn(number: 1) ⇒ String

Examples:

Faker::Books::Lovecraft.fhtagn
  #=> "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn"
Faker::Books::Lovecraft.fhtagn(number: 3)
  #=> "Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fht...

Parameters:

  • number (Integer) (defaults to: 1)

    The number of times to repeat the chant

Returns:

  • (String)

Available since:

  • 1.9.3



32
33
34
# File 'lib/faker/books/lovecraft.rb', line 32

def fhtagn(number: 1)
  Array.new(number) { fetch('lovecraft.fhtagn') }.join('. ')
end

.locationString

Produces the name of a location

Examples:

Faker::Books::Lovecraft.location #=> "Kingsport"

Returns:

  • (String)

Available since:

  • 1.9.3



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

Examples:

Faker::Books::Lovecraft.paragraph
  #=> "Squamous nameless daemoniac fungus ululate. Cyclopean stygian decadent loathsome manuscript tenebrous. Foetid abnormal stench. Dank non-euclidean comprehension eldritch. Charnel singular shunned lurk effulgence fungus."
Faker::Books::Lovecraft.paragraph(sentence_count: 2)
  #=> "Decadent lurk tenebrous loathsome furtive spectral amorphous gibbous. Gambrel eldritch daemoniac cat madness comprehension stygian effulgence."
Faker::Books::Lovecraft.paragraph(sentence_count: 1, random_sentences_to_add: 1)
  #=> "Stench cyclopean fainted antiquarian nameless. Antiquarian ululate tenebrous non-euclidean effulgence."

Parameters:

  • sentence_count (Integer) (defaults to: 3)

    Number of sentences to generate

  • random_sentences_to_add (Integer) (defaults to: 3)

Returns:

  • (String)

Available since:

  • 1.9.3



191
192
193
# File 'lib/faker/books/lovecraft.rb', line 191

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

Examples:

Faker::Books::Lovecraft.paragraph_by_chars
  #=> "Truffaut stumptown trust fund 8-bit messenger bag portland. Meh kombucha selvage swag biodiesel. Lomo kinfolk jean shorts asymmetrical diy. Wayfarers portland twee stumptown. Wes anderson biodiesel retro 90's pabst. Diy echo 90's mixtape semiotics. Cornho."
Faker::Books::Lovecraft.paragraph_by_chars(characters: 128)
  #=> "Effulgence madness noisome. Fungus stygian mortal madness amorphous dank. Decadent noisome hideous effulgence. Tentacles charne."

Parameters:

  • characters (Integer) (defaults to: 256)

    Number of characters to generate in the paragraph

Returns:

  • (String)

Available since:

  • 1.9.3



238
239
240
241
242
243
244
# File 'lib/faker/books/lovecraft.rb', line 238

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

Examples:

Faker::Books::Lovecraft.paragraphs
#=> [
#     "Noisome daemoniac gibbous abnormal antediluvian. Unutterable fung...
#     "Non-euclidean immemorial indescribable accursed furtive. Dank unn...
#     "Charnel antediluvian unnamable cat blasphemous comprehension tene...
#   ]
Faker::Books::Lovecraft.paragraphs(number: 2)
#=> [
#     "Hideous amorphous manuscript antediluvian non-euclidean cat eldri...
#     "Tenebrous unnamable comprehension antediluvian lurk. Lurk spectra...
#   ]

Parameters:

  • number (Integer) (defaults to: 3)

    Number of paragraphs to generate

Returns:

  • (Array<String>)

Available since:

  • 1.9.3



217
218
219
220
221
222
223
# File 'lib/faker/books/lovecraft.rb', line 217

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

Examples:

Faker::Books::Lovecraft.sentence
  #=> "Furtive antiquarian squamous dank cat loathsome amorphous lurk."
Faker::Books::Lovecraft.sentence(word_count: 3)
  #=> "Daemoniac antediluvian fainted squamous comprehension gambrel nameless singular."
Faker::Books::Lovecraft.sentence(word_count: 3, random_words_to_add: 1)
  #=> "Amorphous indescribable tenebrous."
Faker::Books::Lovecraft.sentence(word_count: 3, random_words_to_add: 0, open_compounds_allowed: true)
  #=> "Effulgence unmentionable gambrel."

Parameters:

  • word_count (Integer) (defaults to: 4)

    The number of words to have in the sentence

  • random_words_to_add (Integer) (defaults to: 6)
  • open_compounds_allowed (Boolean) (defaults to: true)

    If true, generated sentence can contain words having additional spaces

Returns:

  • (String)

Available since:

  • 1.9.3



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

Examples:

Faker::Books::Lovecraft.sentences
#=> [
#     "Nameless loathsome decadent gambrel.",
#     "Ululate swarthy immemorial cat madness gibbous unmentionable unnamable.",
#     "Decadent antediluvian non-euclidean tentacles amorphous tenebrous.",
#   ]
Faker::Books::Lovecraft.sentences(number: 2)
#=> [
#     "Antediluvian amorphous unmentionable singular accursed squamous immemorial.",
#     "Gambrel daemoniac gibbous stygian shunned ululate iridescence abnormal.",
#   ]

Parameters:

  • number (Integer) (defaults to: 3)

    Number of sentences to generate

Returns:

  • (Array<String>)

Available since:

  • 1.9.3



164
165
166
167
168
169
170
# File 'lib/faker/books/lovecraft.rb', line 164

def sentences(number: 3)
  [].tap do |sentences|
    1.upto(resolve(number)) do
      sentences << sentence(word_count: 3)
    end
  end
end

.tomeString

Produces the name of a tome

Examples:

Faker::Books::Lovecraft.tome #=> "Book of Eibon"

Returns:

  • (String)

Available since:

  • 1.9.3



58
59
60
# File 'lib/faker/books/lovecraft.rb', line 58

def tome
  fetch('lovecraft.tome')
end

.wordString

Produces a random word

Examples:

Faker::Books::Lovecraft.word #=> "furtive"

Returns:

  • (String)

Available since:

  • 1.9.3



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

Examples:

Faker::Books::Lovecraft.words
#=> [
#     "manuscript",
#     "abnormal",
#     "singular",
#   ]
Faker::Books::Lovecraft.words(number: 2)
#=> [
#     "daemoniac",
#     "cat",
#   ]
Faker::Books::Lovecraft.words(number: 2, spaces_allowed: 1)
#=> [
#     "lurk",
#     "charnel",
#   ]

Parameters:

  • number (Integer) (defaults to: 3)

    Number of words to generate

  • spaces_allowed (Boolean) (defaults to: false)

    If true, generated words can contain spaces

Returns:

  • (Array<String>)

Available since:

  • 1.9.3



132
133
134
135
136
137
138
139
140
# 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)
  words = sample(word_list, resolved_num)
  return words if spaces_allowed

  words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
end