Class: Wiper::Squeegee
- Inherits:
-
Object
- Object
- Wiper::Squeegee
- Defined in:
- lib/wiper/squeegee.rb
Instance Attribute Summary collapse
-
#curtain ⇒ Object
Returns the value of attribute curtain.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#interval ⇒ Object
Returns the value of attribute interval.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize {|_self| ... } ⇒ Squeegee
constructor
A new instance of Squeegee.
- #wipe ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Squeegee
Returns a new instance of Squeegee.
5 6 7 8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#curtain ⇒ Object
Returns the value of attribute curtain.
3 4 5 |
# File 'lib/wiper/squeegee.rb', line 3 def curtain @curtain end |
#direction ⇒ Object
Returns the value of attribute direction.
3 4 5 |
# File 'lib/wiper/squeegee.rb', line 3 def direction @direction end |
#grid ⇒ Object
Returns the value of attribute grid.
3 4 5 |
# File 'lib/wiper/squeegee.rb', line 3 def grid @grid end |
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/wiper/squeegee.rb', line 3 def interval @interval end |
Instance Method Details
#each ⇒ Object
37 38 39 40 41 42 |
# File 'lib/wiper/squeegee.rb', line 37 def each while @index < @limit wipe yield @grid end end |
#wipe ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |