Class: OMF::Rete::FilterTupleStream
- Inherits:
-
ProcessingTupleStream
- Object
- AbstractTupleStream
- ProcessingTupleStream
- OMF::Rete::FilterTupleStream
- Defined in:
- lib/omf_rete/tuple_stream.rb
Overview
A filtering tuple stream calls the associated processing block for every incoming tuple and forwards the incoming tuple if the the block returns true, otherwise it drops the tuple.
Instance Attribute Summary
Attributes inherited from ProcessingTupleStream
Attributes inherited from AbstractTupleStream
Instance Method Summary collapse
-
#check_for_tuple(tuple) ⇒ Object
Return true if
tuple
can be produced by this stream. -
#initialize(project_pattern, description = project_pattern, receiver = nil, &block) ⇒ FilterTupleStream
constructor
A new instance of FilterTupleStream.
Methods inherited from ProcessingTupleStream
#addTuple, #clear, #inDescription=, #on_add, #on_remove, #removeTuple, #source=
Methods inherited from AbstractTupleStream
#describe, #detach, #index_for_binding
Constructor Details
#initialize(project_pattern, description = project_pattern, receiver = nil, &block) ⇒ FilterTupleStream
Returns a new instance of FilterTupleStream.
240 241 242 |
# File 'lib/omf_rete/tuple_stream.rb', line 240 def initialize(project_pattern, description = project_pattern, receiver = nil, &block) super project_pattern, description, description, receiver, &block end |
Instance Method Details
#check_for_tuple(tuple) ⇒ Object
Return true if tuple
can be produced by this stream. For this we need to check first if it would pass this filter before we check if the source for this filter is being able to produce the tuple in question.
TODO: This currently doesn’t work for tuples with wild cards.
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/omf_rete/tuple_stream.rb', line 251 def check_for_tuple(tuple) if @sourcce # should check if +tuple+ has the same size as description if @result_map rtuple = @result_map.collect do |i| tuple[i] end else rtuple = tuple end if @block.call(*rtuple) @source.check_for_tuple(tuple) end end end |