Class: Bmg::Operator::Restrict

Inherits:
Object
  • Object
show all
Includes:
Unary
Defined in:
lib/bmg/operator/restrict.rb

Overview

Restrict operator.

Filters operand’s tuples to those that meet the predicate received at construction.

Instance Attribute Summary

Attributes included from Bmg::Operator

#type

Instance Method Summary collapse

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #update, #visit, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #union, #unspied

Methods included from Algebra::Shortcuts

#image, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix

Constructor Details

#initialize(type, operand, predicate) ⇒ Restrict

Returns a new instance of Restrict.



12
13
14
15
16
# File 'lib/bmg/operator/restrict.rb', line 12

def initialize(type, operand, predicate)
  @type = type
  @operand = operand
  @predicate = predicate
end

Instance Method Details

#bind(binding) ⇒ Object



24
25
26
# File 'lib/bmg/operator/restrict.rb', line 24

def bind(binding)
  Restrict.new(type, operand.bind(binding), predicate.bind(binding))
end

#eachObject



28
29
30
31
32
# File 'lib/bmg/operator/restrict.rb', line 28

def each
  @operand.each do |tuple|
    yield(tuple) if @predicate.evaluate(tuple)
  end
end

#to_astObject



34
35
36
# File 'lib/bmg/operator/restrict.rb', line 34

def to_ast
  [ :restrict, operand.to_ast, predicate.sexpr ]
end