Class: OMF::Rete::AbstractTupleSet
- Inherits:
-
Object
- Object
- OMF::Rete::AbstractTupleSet
- Defined in:
- lib/omf_rete/abstract_tuple_set.rb
Overview
This class maintains a set of tuples and supports a block being attached which is being called whenever a tuple is added or removed.
The TupleSet is defined by a description
.
The description
is an array of the same length as the tuples maintained. Each element, if not nil, names the binding variable associated with it. The position of a binding can be retrieved with index_for_binding
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #addTuple(tuple) ⇒ Object
- #binding_at(index) ⇒ Object
- #describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") ⇒ Object
-
#detach ⇒ Object
Detach all streams from each other as they are no longer in use.
-
#index_for_binding(bname) ⇒ Object
Retunr the index into the tuple for the binding variable
bname
. -
#initialize(description, source = nil) ⇒ AbstractTupleSet
constructor
A new instance of AbstractTupleSet.
-
#on_add(&block) ⇒ Object
Call block for every tuple stored in this set currently and in the future.
- #register_with_store(store, description) ⇒ Object
- #removeTuple(tuple) ⇒ Object
-
#to_a ⇒ Object
Return all stored tuples in an array.
Constructor Details
#initialize(description, source = nil) ⇒ AbstractTupleSet
Returns a new instance of AbstractTupleSet.
22 23 24 25 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 22 def initialize(description, source = nil) @description = description @source = source end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
19 20 21 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 19 def description @description end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 20 def source @source end |
Instance Method Details
#addTuple(tuple) ⇒ Object
41 42 43 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 41 def addTuple(tuple) raise 'Abstract class' end |
#binding_at(index) ⇒ Object
75 76 77 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 75 def binding_at(index) @description[index] end |
#describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") ⇒ Object
79 80 81 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 79 def describe(out = STDOUT, offset = 0, incr = 2, sep = "\n") raise 'Abstract class' end |
#detach ⇒ Object
Detach all streams from each other as they are no longer in use
35 36 37 38 39 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 35 def detach() @source.detach if @source puts ">>> UNREGISTER" @store.unregisterTSet(self) if @store end |
#index_for_binding(bname) ⇒ Object
Retunr the index into the tuple for the binding variable bname
.
Note: This index is different to the set index used in IndexedTupleSet
69 70 71 72 73 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 69 def index_for_binding(bname) @description.find_index do |el| el == bname end end |
#on_add(&block) ⇒ Object
Call block for every tuple stored in this set currently and in the future. In other words, the block may be called even after this method returns.
The block will be called with one parameters, the tuple added.
56 57 58 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 56 def on_add(&block) raise 'Abstract class' end |
#register_with_store(store, description) ⇒ Object
27 28 29 30 31 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 27 def register_with_store(store, description) @store = store raise "BUG ALERT" unless description == @description store.registerTSet(self, description) end |
#removeTuple(tuple) ⇒ Object
45 46 47 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 45 def removeTuple(tuple) raise 'Abstract class' end |
#to_a ⇒ Object
Return all stored tuples in an array.
61 62 63 |
# File 'lib/omf_rete/abstract_tuple_set.rb', line 61 def to_a raise 'Abstract class' end |