Class: LoremIpsumAmet::Base

Inherits:
Object
  • Object
show all
Includes:
Image
Defined in:
lib/lorem_ipsum_amet/base.rb

Instance Method Summary collapse

Methods included from Image

#placeholder_image

Instance Method Details

#c(characters, join_element = "\n") ⇒ Object



60
61
62
# File 'lib/lorem_ipsum_amet/base.rb', line 60

def c(characters, join_element = "\n")
  lorem_ipsum(characters, join: join_element)
end

#long(join_element = "\n") ⇒ Object



47
48
49
# File 'lib/lorem_ipsum_amet/base.rb', line 47

def long(join_element = "\n")
  lorem_ipsum(paragraphs: 8, join: join_element)
end

#lorem_ipsum(cpw = nil, options = {}) ⇒ Object Also known as: text

cpw: characters, paragraphs or words



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lorem_ipsum_amet/base.rb', line 10

def lorem_ipsum(cpw = nil, options = {})
  cpw = { characters: cpw } unless cpw.respond_to?(:merge)
  @params = cpw.merge!(options)

  join_element = params[:join].nil? && params.delete(:html) ? '<br />' : params.delete(:join)

  if params[:characters]
    Character.new(self, params.delete(:characters), join_element).text
  elsif params[:c]
    Character.new(self, params.delete(:c), join_element).text
  elsif params[:paragraphs]
    Paragraph.new(self, params.delete(:paragraphs), join_element).text
  elsif params[:p]
    Paragraph.new(self, params.delete(:p), join_element).text
  elsif params[:words]
    Word.new(self, params.delete(:words), join_element).text
  elsif params[:w]
    Word.new(self, params.delete(:w), join_element).text
  else
    paragraphs.first
  end
end

#medium(join_element = "\n") ⇒ Object



43
44
45
# File 'lib/lorem_ipsum_amet/base.rb', line 43

def medium(join_element = "\n")
  lorem_ipsum(paragraphs: 2, join: join_element)
end

#p(paragraphs, join_element = "\n") ⇒ Object



64
65
66
# File 'lib/lorem_ipsum_amet/base.rb', line 64

def p(paragraphs, join_element = "\n")
  lorem_ipsum(paragraphs: paragraphs, join: join_element)
end

#paragraphsObject



35
36
37
# File 'lib/lorem_ipsum_amet/base.rb', line 35

def paragraphs
  formatted_text.split("\n")
end

#paramsObject



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

def params
  @params ||= {}
end

#random(options = {}) ⇒ Object



72
73
74
75
# File 'lib/lorem_ipsum_amet/base.rb', line 72

def random(options = {})
  _paragraphs = options.delete(:paragraphs) || 1
  Paragraph.new(self, _paragraphs, options[:join_element]).random
end

#shortObject



39
40
41
# File 'lib/lorem_ipsum_amet/base.rb', line 39

def short
  lorem_ipsum(words: 8)
end

#the_lord_of_the_rings_long(join_element = "\n") ⇒ Object



56
57
58
# File 'lib/lorem_ipsum_amet/base.rb', line 56

def the_lord_of_the_rings_long(join_element = "\n")
  lorem_ipsum(words: 500000, join: join_element)
end

#very_long(join_element = "\n") ⇒ Object



51
52
53
# File 'lib/lorem_ipsum_amet/base.rb', line 51

def very_long(join_element = "\n")
  lorem_ipsum(paragraphs: 24, join: join_element)
end

#w(words, join_element = "\n") ⇒ Object



68
69
70
# File 'lib/lorem_ipsum_amet/base.rb', line 68

def w(words, join_element = "\n")
  lorem_ipsum(words: words, join: join_element)
end