Class: Ruleby::Core::PropertyNode

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

Overview

This node class is used for matching properties of a fact.

Instance Attribute Summary

Attributes inherited from AtomNode

#atom

Attributes inherited from ParentNode

#child_nodes

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from AtomNode

#==, #initialize, #shareable?, #to_s

Methods inherited from ParentNode

#add_out_node, #initialize, #modify, #propagate, #propagate_assert, #propagate_modify, #propagate_retract, #retract

Methods inherited from Node

#initialize, #resolve

Methods inherited from Printable

#initialize, #print

Constructor Details

This class inherits a constructor from Ruleby::Core::AtomNode

Instance Method Details

#assert(assertable) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/core/nodes.rb', line 465

def assert(assertable)
  begin
    v = assertable.fact.object.send(@atom.slot)
    assertable.add_tag(@atom.tag, v)
  rescue NoMethodError => e
    @bucket.add_error Error.new(:no_method, :warn, {
        :object => assertable.fact.object.to_s,
        :method => e.name,
        :message => e.message
    })
    return
  end
  begin
    if @atom.proc.arity == 1
      super if @atom.proc.call(v)
    else
      super if @atom.proc.call(v, @atom.value)
    end
  rescue Exception => e
    @bucket.add_error Error.new(:proc_call, :error, {
        :object => assertable.fact.object.to_s,
        :method => @atom.slot,
        :value => v.to_s,
        :message => e.message
    })
  end
end