Class: Wongi::Engine::FilterNode

Inherits:
BetaNode
  • Object
show all
Defined in:
lib/wongi-engine/beta/filter_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, test) ⇒ FilterNode

Returns a new instance of FilterNode.



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

def initialize(parent, test)
  super parent
  self.test = test
end

Instance Attribute Details

#testWongi::Engine::FilterTest



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

def test
  @test
end

Instance Method Details

#beta_activate(token) ⇒ Object



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

def beta_activate(token)
  return if tokens.find { |t| t.duplicate? token }

  return unless test.passes?(token)

  overlay.add_token(token)

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

#beta_deactivate(token) ⇒ Object



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

def beta_deactivate(token)
  overlay.remove_token(token)
  beta_deactivate_children(token: token)
end

#equivalent?(test) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/wongi-engine/beta/filter_node.rb', line 29

def equivalent?(test)
  test == self.test
end

#refresh_child(child) ⇒ Object



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

def refresh_child(child)
  tokens.select { test.passes?(_1) }.each do |token|
    child.beta_activate Token.new(child, token, nil, {})
  end
end