Module: DummyText::Base

Defined in:
lib/dummy_text/base.rb

Defined Under Namespace

Classes: TooMuchError, WrongFormat

Instance Method Summary collapse

Instance Method Details

#dummy_text(arg) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dummy_text/base.rb', line 7

def dummy_text(arg)
  if /(\d+)([c|w|s|p])/i.match(arg)
    count = $1.to_i
    
    case $2.downcase
      when "c" then character(count)
      when "w" then word(count)
      when "s" then sentence(count)
      when "p" then paragraph(count)
    end
  else
    raise WrongFormat, "Your dummy text has a wrong format! DummyText just understands 'Xc' for x characters, 'Xw' for x words, 'Xs' for x sentences, 'Xp' for x paragraphs, 'X' stands for the count."
  end
end