Class: LoremIpsumForgery

Inherits:
Forgery show all
Defined in:
lib/forgeries/lorem_ipsum_forgery.rb

Class Method Summary collapse

Methods inherited from Forgery

dictionaries, formats

Class Method Details

.character(options = {}) ⇒ Object



25
26
27
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 25

def self.character(options={})
  self.characters(1, options)
end

.characters(quantity = 10, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 29

def self.characters(quantity=10, options={})
  options.merge!(:random_limit => lorem_ipsum_characters.length-quantity) if quantity.is_a?(Fixnum)

  lorem_ipsum_characters[range_from_quantity(quantity, options)]
end

.paragraph(options = {}) ⇒ Object



55
56
57
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 55

def self.paragraph(options={})
  self.paragraphs(1, options)
end

.paragraphs(quantity = 2, options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 59

def self.paragraphs(quantity=2, options={})
  options.reverse_merge!(:separator => "\n\n",
                         :wrap => {
                           :start => "",
                           :end => "" },
                         :html => false,
                         :sentences => 3)
  options.merge!(:random_limit => (dictionaries[:lorem_ipsum].length/options[:sentences])-quantity) if quantity.is_a?(Fixnum)

  if options[:html]
    options[:wrap] = { :start => "<p>",
                       :end => "</p>" }
  end

  range = range_from_quantity(quantity, options)
  start = range.first * options[:sentences]

  paragraphs = []

  range.to_a.length.times do |i|
    paragraphs << (
      options[:wrap][:start] +
      dictionaries[:lorem_ipsum][start..(start+options[:sentences]-1)].join(" ") +
      options[:wrap][:end]
    )
    start += options[:sentences]
  end

  paragraphs.join(options[:separator])
end

.sentence(options = {}) ⇒ Object



45
46
47
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 45

def self.sentence(options={})
  self.sentences(1, options)
end

.sentences(quantity = 2, options = {}) ⇒ Object



49
50
51
52
53
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 49

def self.sentences(quantity=2, options={})
  options.merge!(:random_limit => (dictionaries[:lorem_ipsum].length-quantity)) if quantity.is_a?(Fixnum)

  dictionaries[:lorem_ipsum][range_from_quantity(quantity, options)].join(" ")
end

.text(what = :sentence, quantity = 2, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 3

def self.text(what=:sentence, quantity=2, options={})
  case what
  when :character
    self.character(options)
  when :characters
    self.characters(quantity, options)
  when :word
    self.word(options)
  when :words
    self.words(quantity, options)
  when :sentence
    self.sentence(options)
  when :sentences
    self.sentences(quantity, options)
  when :paragraph
    self.paragraph(options)
  when :paragraphs
    self.paragraphs(quantity, options)
  end
end

.word(options = {}) ⇒ Object



35
36
37
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 35

def self.word(options={})
  self.words(1, options)
end

.words(quantity = 10, options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/forgeries/lorem_ipsum_forgery.rb', line 39

def self.words(quantity=10, options={})
  options.merge!(:random_limit => lorem_ipsum_words.length-quantity) if quantity.is_a?(Fixnum)

  lorem_ipsum_words[range_from_quantity(quantity, options)].join(" ")
end