Class: Wongi::Engine::NccNode

Inherits:
BetaNode
  • Object
show all
Includes:
TokenContainer
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, #depth, #refresh, #root?

Methods included from CoreExt

included

Constructor Details

#initialize(parent) ⇒ NccNode

Returns a new instance of NccNode.



8
9
10
# File 'lib/wongi-engine/beta/ncc_node.rb', line 8

def initialize parent
  super
end

Instance Attribute Details

#partnerObject

Returns the value of attribute partner.



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

def partner
  @partner
end

Instance Method Details

#beta_activate(token) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wongi-engine/beta/ncc_node.rb', line 12

def beta_activate token
  return if tokens.find { |t| t.parent == token }
  t = Token.new self, token, nil, {}
  t.overlay.add_token(t, self)
  partner.tokens.each do |ncc_token|
    next unless ncc_token.ancestors.find { |a| a.equal? token }
    t.ncc_results << ncc_token
    ncc_token.owner = t
  end
  if t.ncc_results.empty?
    children.each do |child|
      child.beta_activate Token.new( child, t, nil, { } )
    end
  end
end

#beta_deactivate(token) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wongi-engine/beta/ncc_node.rb', line 28

def beta_deactivate token
  t = tokens.find { |tok| tok.parent == token }
  return unless t
  t.overlay.remove_token(t, self)
  t.deleted!
  partner.tokens.select { |ncc| ncc.owner == t }.each do |ncc_token|
    ncc_token.owner = nil
    t.ncc_results.delete ncc_token
  end
  children.each do |beta|
    beta.tokens.select { |token| token.parent == t }.each do |token|
      beta.beta_deactivate token
    end
  end
end

#ncc_activate(token) ⇒ Object



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

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

#ncc_deactivate(token) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/wongi-engine/beta/ncc_node.rb', line 50

def ncc_deactivate token
  children.each do |beta|
    beta.tokens.select { |t| t.parent == token }.each do |t|
      beta.beta_deactivate t
    end
  end
end

#refresh_child(child) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/wongi-engine/beta/ncc_node.rb', line 58

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