Class: Alf::Engine::Filter

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

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

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

#operandEnumerable (readonly)


21
22
23
# File 'lib/alf/engine/filter.rb', line 21

def operand
  @operand
end

#predicatePredicate (readonly)


24
25
26
# File 'lib/alf/engine/filter.rb', line 24

def predicate
  @predicate
end

Instance Method Details

#_eachObject


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

#argumentsObject


42
43
44
# File 'lib/alf/engine/filter.rb', line 42

def arguments
  [ predicate ]
end