Class: Wongi::Engine::OrNode

Inherits:
BetaNode show all
Defined in:
lib/wongi-engine/beta/or_node.rb

Instance Attribute Summary collapse

Attributes inherited from BetaNode

#children, #parent

Instance Method Summary collapse

Methods inherited from BetaNode

#assignment_node, #beta_deactivate_children, #empty?, #overlay, #root?, #size, #tokens

Methods included from CoreExt

included

Constructor Details

#initialize(parents) ⇒ OrNode

Returns a new instance of OrNode.



6
7
8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#parentsObject (readonly)

Returns the value of attribute parents.



4
5
6
# File 'lib/wongi-engine/beta/or_node.rb', line 4

def parents
  @parents
end

#reteObject (readonly)

Returns the value of attribute rete.



4
5
6
# File 'lib/wongi-engine/beta/or_node.rb', line 4

def rete
  @rete
end

Instance Method Details

#beta_activate(token) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
41
42
# 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

#depthObject



23
24
25
# File 'lib/wongi-engine/beta/or_node.rb', line 23

def depth
  parents.map(&:depth).max + 1
end

#identObject



18
19
20
21
# File 'lib/wongi-engine/beta/or_node.rb', line 18

def ident
  ids = parents.map(&:id).join ", "
  "<R> #{self.class} #{id}, parents #{ids}"
end

#refreshObject



44
45
46
47
48
# 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) ⇒ Object



50
51
52
53
54
# 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