Class: OMF::Rete::FilterTupleStream

Inherits:
ProcessingTupleStream show all
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

#receiver

Attributes inherited from AbstractTupleStream

#description, #source

Instance Method Summary collapse

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