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.2.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…’.



81
82
83
84
# File 'lib/lipsum.rb', line 81

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)


127
128
129
130
131
132
133
134
135
# File 'lib/lipsum.rb', line 127

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



97
98
99
# File 'lib/lipsum.rb', line 97

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

#listsObject

Create lists



102
103
104
# File 'lib/lipsum.rb', line 102

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

#paragraphsObject

Create paragraphs



87
88
89
# File 'lib/lipsum.rb', line 87

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

#to_htmlObject

Retrieve text in HTML format



113
114
115
# File 'lib/lipsum.rb', line 113

def to_html
  @lipsum.to_html
end

#to_sObject Also known as: to_string

Retrieve text



107
108
109
# File 'lib/lipsum.rb', line 107

def to_s
  @lipsum.to_s
end

#wordsObject

Create words



92
93
94
# File 'lib/lipsum.rb', line 92

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