Class: L33tOutput::Line
- Inherits:
-
Object
- Object
- L33tOutput::Line
- Defined in:
- lib/l33t-output/line.rb
Constant Summary collapse
- LETTERS =
('A'..'Z').to_a
- LAG =
20
Instance Attribute Summary collapse
-
#txt ⇒ Object
readonly
Returns the value of attribute txt.
Instance Method Summary collapse
- #display ⇒ Object
- #done? ⇒ Boolean
- #got(i) ⇒ Object
- #incr ⇒ Object
- #indices ⇒ Object
-
#initialize(txt) ⇒ Line
constructor
A new instance of Line.
- #output ⇒ Object
- #rotate ⇒ Object
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
#txt ⇒ Object (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
#display ⇒ Object
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
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 |
#incr ⇒ Object
31 32 33 |
# File 'lib/l33t-output/line.rb', line 31 def incr show << indices.shift end |
#indices ⇒ Object
37 38 39 |
# File 'lib/l33t-output/line.rb', line 37 def indices @indices ||= txt.length.times.to_a.shuffle end |
#output ⇒ Object
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 |
#rotate ⇒ Object
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 |