class Wiper::Squeegee
Attributes
curtain[RW]
direction[RW]
grid[RW]
interval[RW]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/wiper/squeegee.rb, line 5 def initialize @grid = [[0] * 45] * 7 @direction = :east @curtain = false @interval = 0.1 @index = 0 @limit = 45 yield self if block_given? end
Public Instance Methods
direction=(dir)
click to toggle source
# File lib/wiper/squeegee.rb, line 16 def direction= dir @direction = dir @limit = 7 if [:north, :south].include? dir end
each() { |grid| ... }
click to toggle source
# File lib/wiper/squeegee.rb, line 37 def each while @index < @limit wipe yield @grid end end
wipe()
click to toggle source
# File lib/wiper/squeegee.rb, line 21 def wipe @grid.transpose! if [:north, :south].include? @direction @grid.map do |row| row.reverse! if [:north, :west].include? @direction row[@index] = 1 if @index < row.length unless curtain row[@index - 1] = 0 if @index > 0 end row.reverse! if [:north, :west].include? @direction end @grid.transpose! if [:north, :south].include? @direction @grid.interval = @interval @index += 1 end