Class: Faker::CustomIpsum
- Inherits:
-
Object
- Object
- Faker::CustomIpsum
- Defined in:
- lib/blasphemy.rb
Overview
heavily inspired (mildly said) by lorem_ipsum.py from Django contrib/webdesign
Direct Known Subclasses
Instance Attribute Summary collapse
-
#wordlist ⇒ Object
Returns the value of attribute wordlist.
Instance Method Summary collapse
-
#initialize ⇒ CustomIpsum
constructor
A new instance of CustomIpsum.
-
#paragraph ⇒ Object
Returns a randomly generated paragraph of lorem ipsum text.
-
#sentence ⇒ Object
Returns a randomly generated sentence of lorem ipsum text.
- #words(num = 3) ⇒ Object
Constructor Details
#initialize ⇒ CustomIpsum
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
#wordlist ⇒ Object
Returns the value of attribute wordlist.
5 6 7 |
# File 'lib/blasphemy.rb', line 5 def wordlist @wordlist end |
Instance Method Details
#paragraph ⇒ Object
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 |
#sentence ⇒ Object
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 |