Class: Aqueductron::SpontaneousJointPiece
- Inherits:
-
Object
- Object
- Aqueductron::SpontaneousJointPiece
- Includes:
- PieceCommon
- Defined in:
- lib/aqueductron/partition.rb
Instance Attribute Summary collapse
-
#categorize ⇒ Object
readonly
TODO: make private.
-
#make_new_path ⇒ Object
readonly
TODO: make private.
-
#paths ⇒ Object
readonly
TODO: make private.
Instance Method Summary collapse
- #eof ⇒ Object
-
#initialize(paths, categorize, make_new_path) ⇒ SpontaneousJointPiece
constructor
A new instance of SpontaneousJointPiece.
- #receive(msg) ⇒ Object
Methods included from PieceCommon
Constructor Details
#initialize(paths, categorize, make_new_path) ⇒ SpontaneousJointPiece
8 9 10 11 12 |
# File 'lib/aqueductron/partition.rb', line 8 def initialize(paths, categorize, make_new_path) @categorize = categorize @make_new_path = make_new_path @paths = paths end |
Instance Attribute Details
#categorize ⇒ Object (readonly)
TODO: make private
7 8 9 |
# File 'lib/aqueductron/partition.rb', line 7 def categorize @categorize end |
#make_new_path ⇒ Object (readonly)
TODO: make private
7 8 9 |
# File 'lib/aqueductron/partition.rb', line 7 def make_new_path @make_new_path end |
#paths ⇒ Object (readonly)
TODO: make private
7 8 9 |
# File 'lib/aqueductron/partition.rb', line 7 def paths @paths end |
Instance Method Details
#eof ⇒ Object
32 33 34 35 36 |
# File 'lib/aqueductron/partition.rb', line 32 def eof go = ->(v) { v.result? ? v : v.eof } new_map = paths.map_values(&go) construct_compound_result(new_map) end |
#receive(msg) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aqueductron/partition.rb', line 15 def receive(msg) category = categorize.call(msg) new_map = if (paths.key? category) paths else paths[category] = make_new_path.call(category) # todo: don't update paths end go = ->(v) { v.result? ? v : v.receive(msg) } new_map[category] = go.call(new_map[category]) #todo: don't mutate if (new_map.values.all? &:result? ) construct_compound_result(new_map) else SpontaneousJointPiece.new(new_map, categorize, make_new_path) end end |