Class: L33tOutput::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/l33t-output/line.rb

Constant Summary collapse

LETTERS =
('A'..'Z').to_a
LAG =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txt) ⇒ Line

Returns a new instance of Line.



7
8
9
10
11
12
# File 'lib/l33t-output/line.rb', line 7

def initialize(txt)
  @txt = txt.upcase.strip
  @out = $stdout
  @counter = 0
  @show = []
end

Instance Attribute Details

#txtObject (readonly)

Returns the value of attribute txt.



5
6
7
# File 'lib/l33t-output/line.rb', line 5

def txt
  @txt
end

Instance Method Details

#displayObject



23
24
25
# File 'lib/l33t-output/line.rb', line 23

def display
  txt.length.times.map{|i| got(i) or LETTERS.sample }.join
end

#done?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/l33t-output/line.rb', line 27

def done?
  indices.empty?
end

#got(i) ⇒ Object



41
42
43
# File 'lib/l33t-output/line.rb', line 41

def got(i)
  txt[i] if show.include? i
end

#incrObject



31
32
33
# File 'lib/l33t-output/line.rb', line 31

def incr
  show << indices.shift
end

#indicesObject



37
38
39
# File 'lib/l33t-output/line.rb', line 37

def indices
  @indices ||= txt.length.times.to_a.shuffle
end

#outputObject



14
15
16
17
18
19
20
21
# File 'lib/l33t-output/line.rb', line 14

def output
  rotate do
    out.print "\r#{display}"
    out.flush
    sleep 0.01
  end
  out.puts
end

#rotateObject



45
46
47
48
49
50
51
# File 'lib/l33t-output/line.rb', line 45

def rotate
  begin
    @counter += 1
    incr if @counter % LAG
    yield
  end while not done?
end