Class: Simulator::Print

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/logpoop/simulator/print.rb

Instance Method Summary collapse

Methods included from Base

#clear_screen, included, #simulate, #stop

Constructor Details

#initialize(out, text, cols) ⇒ Print

Returns a new instance of Print.



13
14
15
16
17
# File 'lib/logpoop/simulator/print.rb', line 13

def initialize(out, text, cols)
  @out  = out  # terminal
  @text = text # text to print
  @cols = cols # width of this terminal
end

Instance Method Details

#fake_itObject



5
6
7
8
9
10
11
# File 'lib/logpoop/simulator/print.rb', line 5

def fake_it
  while !@stop do
    @out.puts make_text(@text)
    sleep rand(0.01..0.1)
  end
  clear_screen(@out)
end

#make_text(t) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/logpoop/simulator/print.rb', line 19

def make_text(t)
  width       = rand((@cols - 5)..@cols)
  times       = width / (t.length + 1) # 1 is for space
  front_space = (' ' * (@cols - width))
  words       = times.times.map{ maybe_mess_with(t) }.join(' ')
  front_space + words
end

#maybe_mess_with(t) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/logpoop/simulator/print.rb', line 27

def maybe_mess_with(t)
  if rand(2) == 1
    t.each_char.map do |a|
      if rand(2) == 1
        a.upcase
      else
        a.downcase
      end
    end.join('')
  else
    t
  end    
end