class TRecs::SwipeStrategy
Attributes
hider[R]
message[R]
swiper[R]
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
TRecs::Strategy::new
# File lib/trecs/strategies/swipe_strategy.rb, line 10 def initialize(options={}) super(options) @message = options.fetch(:message) @command = options.fetch(:command) { nil } @swiper = options.fetch(:swiper) { "|" } @hider = options.fetch(:hider) { "*" } @frames = {} end
Public Instance Methods
perform()
click to toggle source
# File lib/trecs/strategies/swipe_strategy.rb, line 19 def perform message.each_line do |line| curr_message = " %-#{max_line_size}s " % line.chomp curr_message.length.times do |i| current_time = step.to_i * i c = curr_message.dup c[i] = swiper (i+1..c.length-3).each do |j| c[j] = hider end c = c[1..-2] @frames[current_time] ||= "" @frames[current_time] << c.strip + "\n" end end cleanup_frames end
Private Instance Methods
cleanup_frames()
click to toggle source
# File lib/trecs/strategies/swipe_strategy.rb, line 43 def cleanup_frames @frames.each do |t, c| @frames[t] = @frames[t].chomp end end
max_line_size()
click to toggle source
# File lib/trecs/strategies/swipe_strategy.rb, line 49 def max_line_size message.each_line.inject(0) { |max, l| l.size > max ? l.size : max } end