Class: Wongi::Engine::NccNode

Inherits:
BetaNode
  • Object
show all
Defined in:
lib/wongi-engine/beta/ncc_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?, #initialize, #overlay, #refresh, #root?, #size, #tokens

Methods included from CoreExt

included

Constructor Details

This class inherits a constructor from Wongi::Engine::BetaNode

Instance Attribute Details

#partnerObject

Returns the value of attribute partner.



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

def partner
  @partner
end

Instance Method Details

#beta_activate(token) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wongi-engine/beta/ncc_node.rb', line 6

def beta_activate(token)
  # p beta_activate: {class: self.class, object_id:, token:}
  return if tokens.find { |t| t.duplicate? token }

  overlay.add_token(token)
  partner.tokens.each do |ncc_token|
    if partner.owner_for(ncc_token) == token
      overlay.add_ncc_token(token, ncc_token)
    end
  end
  return if overlay.ncc_tokens_for(token).any?

  children.each do |child|
    child.beta_activate Token.new(child, token, nil, {})
  end
end

#beta_deactivate(token) ⇒ Object



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

def beta_deactivate(token)
  # p beta_deactivate: {class: self.class, object_id:, token:}
  overlay.remove_token(token)
  beta_deactivate_children(token: token)
end

#ncc_activate(token) ⇒ Object



29
30
31
32
33
34
# File 'lib/wongi-engine/beta/ncc_node.rb', line 29

def ncc_activate(token)
  # p ncc_activate: {class: self.class, object_id:, token:}
  children.each do |child|
    child.beta_activate Token.new(child, token, nil, {})
  end
end

#ncc_deactivate(token) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/wongi-engine/beta/ncc_node.rb', line 36

def ncc_deactivate(token)
  # p ncc_deactivate: {class: self.class, object_id:, token:}
  children.each do |beta|
    beta.tokens.select { |t| t.child_of?(token) }.each do |t|
      beta.beta_deactivate t
    end
  end
end

#refresh_child(child) ⇒ Object



45
46
47
48
49
# File 'lib/wongi-engine/beta/ncc_node.rb', line 45

def refresh_child(child)
  tokens.each do |token|
    child.beta_activate Token.new(child, token, nil, {}) if overlay.ncc_tokens_for(token).empty?
  end
end