Class: Ruleby::Core::CollectNode
- Inherits:
-
BaseBridgeNode
- Object
- Printable
- Node
- ParentNode
- BaseBridgeNode
- Ruleby::Core::CollectNode
- Defined in:
- lib/core/nodes.rb
Instance Attribute Summary
Attributes inherited from ParentNode
Attributes inherited from Printable
Instance Method Summary collapse
-
#initialize(bucket, pattern) ⇒ CollectNode
constructor
A new instance of CollectNode.
- #propagate_assert(fact) ⇒ Object
- #retract(assertable) ⇒ Object
Methods inherited from BaseBridgeNode
Methods inherited from ParentNode
#add_out_node, #assert, #modify, #propagate, #propagate_modify, #propagate_retract
Methods inherited from Node
Methods inherited from Printable
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 |