Class: Alf::Engine::Filter
- Inherits:
-
Object
- Object
- Alf::Engine::Filter
- Includes:
- Cog
- Defined in:
- lib/alf/engine/filter.rb
Overview
Filters operand using a tuple predicate.
Example
rel = [
{:name => "Smith"},
{:name => "Jones"}
]
Filter.new(rel, Predicate.parse("name =~ /^J/")).to_a
# => [
# {:name => "Jones"}
# ]
Constant Summary
Constants included from Cog
Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS
Instance Attribute Summary collapse
-
#operand ⇒ Enumerable
readonly
The operand.
-
#predicate ⇒ Predicate
readonly
Filtering predicate.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, predicate, expr = nil, compiler = nil) ⇒ Filter
constructor
Creates a Filter instance.
Methods included from Cog
#children, #each, #options, #to_s
Methods included from Compiler::Cog
#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation
Constructor Details
#initialize(operand, predicate, expr = nil, compiler = nil) ⇒ Filter
Creates a Filter instance
27 28 29 30 31 |
# File 'lib/alf/engine/filter.rb', line 27 def initialize(operand, predicate, expr = nil, compiler = nil) super(expr, compiler) @operand = operand @predicate = predicate end |
Instance Attribute Details
#operand ⇒ Enumerable (readonly)
Returns The operand.
21 22 23 |
# File 'lib/alf/engine/filter.rb', line 21 def operand @operand end |
#predicate ⇒ Predicate (readonly)
Returns Filtering predicate.
24 25 26 |
# File 'lib/alf/engine/filter.rb', line 24 def predicate @predicate end |
Instance Method Details
#_each ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/alf/engine/filter.rb', line 34 def _each scope = tuple_scope operand.each do |tuple| t = scope.__set_tuple(tuple) yield(tuple) if @predicate.evaluate(t) end end |
#arguments ⇒ Object
42 43 44 |
# File 'lib/alf/engine/filter.rb', line 42 def arguments [ predicate ] end |