Class: Aqueductron::Piece

Inherits:
Object
  • Object
show all
Includes:
PieceCommon
Defined in:
lib/aqueductron/piece.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PieceCommon

#flow, #result?

Constructor Details

#initialize(destination, what_to_do) ⇒ Piece

Returns a new instance of Piece.



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

def initialize(destination, what_to_do)
  @destination = destination
  @what_to_do = what_to_do
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



5
6
7
# File 'lib/aqueductron/piece.rb', line 5

def destination
  @destination
end

Instance Method Details

#eofObject



17
18
19
# File 'lib/aqueductron/piece.rb', line 17

def eof
  send_eof
end

#pass_on(msg, what_to_do_next) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/aqueductron/piece.rb', line 21

def pass_on(msg, what_to_do_next)
  next_destination = @destination.receive(msg)
  if (next_destination.result?) then
    next_destination
  else
    Piece.new(next_destination, what_to_do_next)
  end
end

#receive(msg) ⇒ Object



13
14
15
# File 'lib/aqueductron/piece.rb', line 13

def receive(msg)
  @what_to_do.call(self, msg)
end

#send_eofObject



29
30
31
# File 'lib/aqueductron/piece.rb', line 29

def send_eof
  @destination.eof
end