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

#_count, #count, #debug, empty, #empty?, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #visit, #with_type, #with_type_attrlist, #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, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap

Methods included from Algebra::Shortcuts

#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where

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

#delete(predicate = Predicate.tautology) ⇒ Object



43
44
45
# File 'lib/bmg/operator/restrict.rb', line 43

def delete(predicate = Predicate.tautology)
  operand.delete(predicate & self.predicate)
end

#eachObject



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

def each
  return to_enum unless block_given?
  @operand.each do |tuple|
    yield(tuple) if @predicate.evaluate(tuple)
  end
end

#insert(tuple) ⇒ Object



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

def insert(tuple)
  operand.insert(tuple)
end

#to_astObject



47
48
49
# File 'lib/bmg/operator/restrict.rb', line 47

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

#update(updating, predicate = Predicate.tautology) ⇒ Object



39
40
41
# File 'lib/bmg/operator/restrict.rb', line 39

def update(updating, predicate = Predicate.tautology)
  operand.update(updating, predicate & self.predicate)
end