Class: Turbine::Pipeline::Filter
- Includes:
- Trace::Transparent
- Defined in:
- lib/turbine/pipeline/filter.rb
Overview
Emits only those values in the pipeline which satisfy the filter
. Filter is to Pipeline as select
is to Enumerable.
Filter.new { |x| firewall.permitted?(x) }
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Segment
Instance Method Summary collapse
-
#initialize(&block) ⇒ Filter
constructor
Public: Creates a new Filter segment.
-
#next ⇒ Object
Public: Runs the pipeline continuously until a value which matches the filter is found, then that value is emitted.
Methods included from Trace::Transparent
Methods inherited from Segment
#append, #each, #inspect, #rewind, #to_s, #trace, #tracing=
Constructor Details
#initialize(&block) ⇒ Filter
Public: Creates a new Filter segment.
You may opt to use the Filter class directly, passing a block when initializing which is used to control which values are emitted. Alternatively, provide no block and use a subclass with a custom filter
method.
Without a filter block, all elements are emitted.
block - An optional block used to select which values are emitted by
the filter.
Returns a Filter.
24 25 26 27 |
# File 'lib/turbine/pipeline/filter.rb', line 24 def initialize(&block) @filter = (block || method(:filter)) super() end |
Instance Method Details
#next ⇒ Object
Public: Runs the pipeline continuously until a value which matches the filter is found, then that value is emitted.
Returns an object.
33 34 35 36 37 38 |
# File 'lib/turbine/pipeline/filter.rb', line 33 def next # Discard non-matching values. nil until (value = input) && @filter.call(value) handle_value(value) end |