Class: Wongi::Engine::AssignmentNode

Inherits:
BetaNode
  • Object
show all
Defined in:
lib/wongi-engine/beta/assignment_node.rb

Instance Attribute Summary collapse

Attributes inherited from BetaNode

#children, #parent, #rete

Instance Method Summary collapse

Methods inherited from BetaNode

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

Methods included from CoreExt

included

Constructor Details

#initialize(parent, variable, body) ⇒ AssignmentNode

Returns a new instance of AssignmentNode.



5
6
7
8
9
# File 'lib/wongi-engine/beta/assignment_node.rb', line 5

def initialize(parent, variable, body)
  super(parent)
  @variable = variable
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/wongi-engine/beta/assignment_node.rb', line 3

def body
  @body
end

#variableObject (readonly)

Returns the value of attribute variable.



3
4
5
# File 'lib/wongi-engine/beta/assignment_node.rb', line 3

def variable
  @variable
end

Instance Method Details

#beta_activate(token, _wme = nil, _assignments = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/wongi-engine/beta/assignment_node.rb', line 11

def beta_activate(token, _wme = nil, _assignments = {})
  return if tokens.find { |t| t.duplicate? token }

  overlay.add_token(token)
  children.each do |child|
    value = body.respond_to?(:call) ? body.call(token) : body
    child.beta_activate Token.new(child, token, nil, { variable => value })
  end
end

#beta_deactivate(token) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wongi-engine/beta/assignment_node.rb', line 21

def beta_deactivate(token)
  overlay.remove_token(token)
  children.each do |child|
    child.tokens.each do |t|
      if t.child_of?(token)
        child.beta_deactivate t
        # token.destroy
      end
    end
  end
end

#refresh_child(child) ⇒ Object



33
34
35
36
37
# File 'lib/wongi-engine/beta/assignment_node.rb', line 33

def refresh_child(child)
  tokens.each do |token|
    child.beta_activate Token.new(child, token, nil, { variable => body.respond_to?(:call) ? body.call(token) : body })
  end
end