Class: Bmg::Operator::Extend

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

Overview

Extend operator.

Extends operand’s tuples with attributes resulting from given computations

Example:

[{ a: 1 }] extend { b: ->(t){ 2 } } => [{ a: 1, b: 2 }]

Instance Attribute Summary

Attributes included from Bmg::Operator

#type

Instance Method Summary collapse

Methods included from Unary

#bind

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#bind, #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, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap

Methods included from Algebra::Shortcuts

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

Constructor Details

#initialize(type, operand, extension) ⇒ Extend

Returns a new instance of Extend.



16
17
18
19
20
# File 'lib/bmg/operator/extend.rb', line 16

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

Instance Method Details

#_countObject



59
60
61
# File 'lib/bmg/operator/extend.rb', line 59

def _count
  operand._count
end

#delete(predicate = Predicate.tautology) ⇒ Object



49
50
51
# File 'lib/bmg/operator/extend.rb', line 49

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

#eachObject



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

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

#insert(arg) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/bmg/operator/extend.rb', line 35

def insert(arg)
  case arg
  when Hash       then operand.insert(allbut_extkeys(arg))
  when Relation   then operand.insert(arg.allbut(extension.keys))
  when Enumerable then operand.insert(arg.map{|t| allbut_extkeys(t) })
  else
    super
  end
end

#to_astObject



53
54
55
# File 'lib/bmg/operator/extend.rb', line 53

def to_ast
  [ :extend, operand.to_ast, extension.dup ]
end

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



45
46
47
# File 'lib/bmg/operator/extend.rb', line 45

def update(tuple, predicate = Predicate.tautology)
  operand.update(allbut_extkeys(tuple), predicate)
end