class Faker::Lovecraft

Public Class Methods

deity() click to toggle source
# File lib/faker/lovecraft.rb, line 12
def deity
  fetch('lovecraft.deity')
end
fhtagn(number_of = 1) click to toggle source
# File lib/faker/lovecraft.rb, line 8
def fhtagn(number_of = 1)
  Array.new(number_of) { fetch('lovecraft.fhtagn') }.join('. ')
end
location() click to toggle source
# File lib/faker/lovecraft.rb, line 4
def location
  fetch('lovecraft.location')
end
paragraph(sentence_count = 3, random_sentences_to_add = 3) click to toggle source
# File lib/faker/lovecraft.rb, line 47
def paragraph(sentence_count = 3, random_sentences_to_add = 3)
  sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ')
end
paragraph_by_chars(chars = 256) click to toggle source
# File lib/faker/lovecraft.rb, line 59
def paragraph_by_chars(chars = 256)
  paragraph = paragraph(3)

  paragraph += ' ' + paragraph(3) while paragraph.length < chars

  paragraph[0...chars - 1] + '.'
end
paragraphs(paragraph_count = 3) click to toggle source
# File lib/faker/lovecraft.rb, line 51
def paragraphs(paragraph_count = 3)
  [].tap do |paragraphs|
    1.upto(resolve(paragraph_count)) do
      paragraphs << paragraph(3)
    end
  end
end
sentence(word_count = 4, random_words_to_add = 6) click to toggle source
# File lib/faker/lovecraft.rb, line 20
def sentence(word_count = 4, random_words_to_add = 6)
  words(word_count + rand(random_words_to_add.to_i).to_i, true).join(' ').capitalize + '.'
end
sentences(sentence_count = 3) click to toggle source
# File lib/faker/lovecraft.rb, line 39
def sentences(sentence_count = 3)
  [].tap do |sentences|
    1.upto(resolve(sentence_count)) do
      sentences << sentence(3)
    end
  end
end
tome() click to toggle source
# File lib/faker/lovecraft.rb, line 16
def tome
  fetch('lovecraft.tome')
end
word() click to toggle source
# File lib/faker/lovecraft.rb, line 24
def word
  random_word = sample(translate('faker.lovecraft.words'))
  random_word =~ /\s/ ? word : random_word
end
words(num = 3, spaces_allowed = false) click to toggle source
# File lib/faker/lovecraft.rb, line 29
def words(num = 3, spaces_allowed = false)
  resolved_num = resolve(num)
  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

Private Class Methods

resolve(value) click to toggle source

If an array or range is passed, a random value will be selected. All other values are simply returned.

# File lib/faker/lovecraft.rb, line 71
def resolve(value)
  case value
  when Array then sample(value)
  when Range then rand value
  else value
  end
end