class Wongi::Engine::OrNode

Attributes

parents[R]
rete[R]

Public Class Methods

new(parents) click to toggle source
Calls superclass method Wongi::Engine::BetaNode::new
# File lib/wongi-engine/beta/or_node.rb, line 6
def initialize(parents)
  super nil
  @parents = parents
  parents.each do |parent|
    parent.children << self
  end
  retes = parents.map(&:rete).uniq
  raise "Cannot combine variants from several Retes" if retes.size > 1

  @rete = retes.first
end

Public Instance Methods

beta_activate(token) click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 27
def beta_activate(token)
  # p beta_activate: {class: self.class, object_id:, token:}
  return if tokens.find { token.duplicate?(_1) }

  overlay.add_token(token)

  children.each do |child|
    child.beta_activate(Token.new(child, token, nil))
  end
end
beta_deactivate(token) click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 38
def beta_deactivate(token)
  # p beta_deactivate: {class: self.class, object_id:, token:}
  overlay.remove_token(token)
  beta_deactivate_children(token: token)
end
depth() click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 23
def depth
  parents.map(&:depth).max + 1
end
ident() click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 18
def ident
  ids = parents.map(&:id).join ", "
  "<R> #{self.class} #{id}, parents #{ids}"
end
refresh() click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 44
def refresh
  parents.each do |parent|
    parent.refresh_child self
  end
end
refresh_child(child) click to toggle source
# File lib/wongi-engine/beta/or_node.rb, line 50
def refresh_child(child)
  tokens.each do |token|
    child.beta_activate(Token.new(child, token, nil))
  end
end