Class: Faker::CustomIpsum

Inherits:
Object
  • Object
show all
Defined in:
lib/blasphemy.rb

Overview

heavily inspired (mildly said) by lorem_ipsum.py from Django contrib/webdesign

Direct Known Subclasses

BaconIpsum, MetalIpsum, SamuelLIpsum, TabulaIpsum

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCustomIpsum

Returns a new instance of CustomIpsum.



7
8
9
# File 'lib/blasphemy.rb', line 7

def initialize
  raise 'Doh! You are trying to instantiate an abstract class!'
end

Instance Attribute Details

#wordlistObject

Returns the value of attribute wordlist.



5
6
7
# File 'lib/blasphemy.rb', line 5

def wordlist
  @wordlist
end

Instance Method Details

#paragraphObject

Returns a randomly generated paragraph of lorem ipsum text. The paragraph consists of between 1 and 4 sentences, inclusive.



30
31
32
# File 'lib/blasphemy.rb', line 30

def paragraph
  ((1..(rand(3)+2)).map{sentence}).join(" ")
end

#sentenceObject

Returns a randomly generated sentence of lorem ipsum text. The first word is capitalized, and the sentence ends in either a period or question mark. Commas are added at random.



17
18
19
20
21
22
23
24
25
26
# File 'lib/blasphemy.rb', line 17

def sentence
  # Determine the number of comma-separated sections and number of words in
  # each section for this sentence.
  sections = []
  1.upto(rand(5)+1) do
    sections << (words(rand(9)+3).join(" "))
  end
  s = sections.join(", ")
  return s.capitalize + ".?!".slice(rand(3),1)
end

#words(num = 3) ⇒ Object



11
12
13
# File 'lib/blasphemy.rb', line 11

def words(num = 3)
  @wordlist.shuffle[0, num]
end