Class: Ruleby::Core::ParentNode

Inherits:
Node show all
Defined in:
lib/core/nodes.rb

Overview

This is the base class for all nodes in the network that output to some other node (i.e. they are not at the bottom). It contains methods for propagating match results.

Instance Attribute Summary collapse

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from Node

#resolve

Methods inherited from Printable

#print

Constructor Details

#initialize(bucket) ⇒ ParentNode

Returns a new instance of ParentNode.



302
303
304
305
# File 'lib/core/nodes.rb', line 302

def initialize(bucket)
  super
  @out_nodes = {}
end

Instance Attribute Details

#child_nodesObject (readonly)

Returns the value of attribute child_nodes.



301
302
303
# File 'lib/core/nodes.rb', line 301

def child_nodes
  @child_nodes
end

Instance Method Details

#add_out_node(node, path, atom = nil) ⇒ Object



307
308
309
310
# File 'lib/core/nodes.rb', line 307

def add_out_node(node, path, atom=nil)
  @out_nodes[node] = [] unless @out_nodes[node]
  @out_nodes[node] << path
end

#assert(assertable) ⇒ Object



341
342
343
# File 'lib/core/nodes.rb', line 341

def assert(assertable)
  propagate_assert(assertable)
end

#modify(assertable) ⇒ Object



349
350
351
# File 'lib/core/nodes.rb', line 349

def modify(assertable)
  raise "Modify not supported by default - its only used for :collect.  This must be a bug"
end

#propagate(propagation_method, assertable, out_nodes = @out_nodes) ⇒ Object



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/core/nodes.rb', line 316

def propagate(propagation_method, assertable, out_nodes=@out_nodes)
  out_nodes.each do |out_node, paths|
    if assertable.respond_to?(:paths)
      continuing_paths =  paths & assertable.paths
      unless continuing_paths.empty?
        begin
          out_node.send(propagation_method, Assertion.new(assertable.fact, continuing_paths))
        rescue => e
          @bucket.add_error Error.new(:unknown, :error, {:type => e.class, :message => e.message})
        end
      end
    else
      begin
        out_node.send(propagation_method, assertable)
      rescue => e
        @bucket.add_error Error.new(:unknown, :error, {:type => e.class, :message => e.message})
      end
    end
  end
end

#propagate_assert(assertable, out_nodes = @out_nodes) ⇒ Object



345
346
347
# File 'lib/core/nodes.rb', line 345

def propagate_assert(assertable,out_nodes=@out_nodes)
  propagate(:assert, assertable, out_nodes)
end

#propagate_modify(assertable, out_nodes = @out_nodes) ⇒ Object



353
354
355
# File 'lib/core/nodes.rb', line 353

def propagate_modify(assertable,out_nodes=@out_nodes)
  propagate(:modify, assertable, out_nodes)
end

#propagate_retract(assertable, out_nodes = @out_nodes) ⇒ Object



337
338
339
# File 'lib/core/nodes.rb', line 337

def propagate_retract(assertable,out_nodes=@out_nodes)
  propagate(:retract, assertable, out_nodes)
end

#retract(assertable) ⇒ Object



312
313
314
# File 'lib/core/nodes.rb', line 312

def retract(assertable)
  propagate_retract(assertable)
end