Class: Ruleby::Core::CollectNode

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

Instance Attribute Summary

Attributes inherited from ParentNode

#child_nodes

Attributes inherited from Printable

#parent_nodes

Instance Method Summary collapse

Methods inherited from BaseBridgeNode

#assert

Methods inherited from ParentNode

#add_out_node, #assert, #modify, #propagate, #propagate_modify, #propagate_retract

Methods inherited from Node

#resolve

Methods inherited from Printable

#print

Constructor Details

#initialize(bucket, pattern) ⇒ CollectNode

Returns a new instance of CollectNode.



612
613
614
615
616
617
618
619
620
# File 'lib/core/nodes.rb', line 612

def initialize(bucket, pattern)
  super
  @collection_memory = Fact.new([], :internal)
  @should_modify = false
  # not really sure what to do about this. might just need to handle nil's
  # using a puts a limit on how many facts can be asserted before this feature breaks
  # it might be best to get a handle to WorkingMemory in order to get the real
#      @collection_memory.recency = 0
end

Instance Method Details

#propagate_assert(fact) ⇒ Object



631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/core/nodes.rb', line 631

def propagate_assert(fact)
  if block_given?
    yield fact
  else
    @collection_memory.object << fact
    @collection_memory.recency = fact.recency
  end

  if @should_modify
    propagate_modify(MatchContext.new(@collection_memory, create_match_result))
  else
    if @collection_memory.object.size > 0
      @should_modify = true
      super(MatchContext.new(@collection_memory, create_match_result))
    end
  end
end

#retract(assertable) ⇒ Object



622
623
624
625
626
627
628
629
# File 'lib/core/nodes.rb', line 622

def retract(assertable)
  fact = assertable.fact
  propagate_retract(@collection_memory)
  propagate_assert(fact) do
    @collection_memory.object.delete_if {|a| a == fact.object}
    @should_modify = false
  end
end