Class: Aqueductron::Inlet

Inherits:
Object
  • Object
show all
Defined in:
lib/aqueductron/inlet.rb

Instance Method Summary collapse

Constructor Details

#initialize(next_piece, done_or_not = :done) ⇒ Inlet

Returns a new instance of Inlet.



3
4
5
6
# File 'lib/aqueductron/inlet.rb', line 3

def initialize(next_piece, done_or_not = :done)
  @next_piece = next_piece
  @done_or_not = done_or_not
end

Instance Method Details

#flow(source) ⇒ Object



8
9
10
# File 'lib/aqueductron/inlet.rb', line 8

def flow(source)
  flow_internal(source.each)
end

#flow_internal(source) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aqueductron/inlet.rb', line 12

def flow_internal(source)
  result = begin
             response = @next_piece.receive(source.next)
             if (response.result?) then
               response
             else #it's another piece
               Inlet.new(response, @done_or_not).flow_internal(source)
             end
           rescue StopIteration
             if (@done_or_not == :done) then
               @next_piece.eof
             else
               @next_piece
             end
           end
end