Class: Stages::Limit

Inherits:
Stage
  • Object
show all
Defined in:
lib/stages/limit.rb

Instance Attribute Summary

Attributes inherited from Stage

#source

Instance Method Summary collapse

Methods inherited from Stage

#die, #done?, #drop_leftmost!, #each, #end?, #handle_value, #initialize_loop, #input, #length, #output, #root_source, #run, #source_empty?, #to_enum, #|

Constructor Details

#initialize(allowed) ⇒ Limit

Returns a new instance of Limit.



3
4
5
6
7
# File 'lib/stages/limit.rb', line 3

def initialize(allowed)
  @allowed = allowed
  @sent = 0
  super()
end

Instance Method Details

#processObject



9
10
11
12
13
14
# File 'lib/stages/limit.rb', line 9

def process
  while @sent < @allowed
    handle_value input
    @sent += 1
  end
end

#resetObject



16
17
18
19
# File 'lib/stages/limit.rb', line 16

def reset
  @sent = 0
  super()
end