class Aqueductron::SpontaneousJointPiece

Attributes

categorize[R]
make_new_path[R]
paths[R]

Public Class Methods

new(paths, categorize, make_new_path) click to toggle source
# 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

Public Instance Methods

draw() click to toggle source
# File lib/aqueductron/partition.rb, line 38
def draw
  ducts = Drawing.draw_multiple_paths(@paths)
  paths = (ducts + ["+?"]).flatten
  Drawing.horizontal_concat(Drawing.joint_prefix, paths)
end
eof() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

construct_compound_result(paths) click to toggle source
# File lib/aqueductron/partition.rb, line 45
def construct_compound_result(paths)
  CompoundResult.new(paths)
end