Class: Lipsum

Inherits:
Object
  • Object
show all
Defined in:
lib/lipsum.rb,
lib/lipsum/version.rb

Defined Under Namespace

Classes: AllTypes, Bytes, Lists, Paragraphs, Words

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = true) ⇒ Lipsum

If start is set to true, the placeholder text will start with ‘Lorem ipsum dolor sit amet…’.



89
90
91
92
# File 'lib/lipsum.rb', line 89

def initialize(start = true)
  @start = start
  @lipsum = nil
end

Class Method Details

.method_missing(id, *args) ⇒ Object

method_missing allow you to use

Lipsum#paragraphs
Lipsum#paragraphs!
Lipsum#words
Lipsum#words!
Lipsum#bytes
Lipsum#bytes!
Lipsum#lists
Lipsum#lists!

Raises:

  • (NoMethodError)


135
136
137
138
139
140
141
142
143
# File 'lib/lipsum.rb', line 135

def self.method_missing(id, *args)
  start = (id.id2name)[-1].chr == "!"
  method = (id.id2name).gsub( /!$/, "" )
  
  if ["paragraphs", "words", "bytes", "lists"].include?(method)
    return Lipsum.new(start).send(method)
  end
  raise NoMethodError, "undefined method `#{id.id2name}' for Lipsum:Class", caller
end

Instance Method Details

#bytesObject

Create bytes



105
106
107
# File 'lib/lipsum.rb', line 105

def bytes
  @lipsum = Bytes.new(@start)
end

#listsObject

Create lists



110
111
112
# File 'lib/lipsum.rb', line 110

def lists
  @lipsum = Lists.new(@start)
end

#paragraphsObject

Create paragraphs



95
96
97
# File 'lib/lipsum.rb', line 95

def paragraphs
  @lipsum = Paragraphs.new(@start)
end

#to_htmlObject

Retrieve text in HTML format



121
122
123
# File 'lib/lipsum.rb', line 121

def to_html
  @lipsum.to_html
end

#to_sObject Also known as: to_string

Retrieve text



115
116
117
# File 'lib/lipsum.rb', line 115

def to_s
  @lipsum.to_s
end

#wordsObject

Create words



100
101
102
# File 'lib/lipsum.rb', line 100

def words
  @lipsum = Words.new(@start)
end