Class: Bmg::Operator::Transform

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

Overview

Transform operator.

Transforms existing attributes through computations

Example:

[{ a: 1 }] transform { a: ->(t){ t[:a]*2 } } => [{ a: 4 }]

Constant Summary collapse

DEFAULT_OPTIONS =
{}

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

#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #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, transformation, options = {}) ⇒ Transform

Returns a new instance of Transform.



17
18
19
20
21
22
# File 'lib/bmg/operator/transform.rb', line 17

def initialize(type, operand, transformation, options = {})
  @type = type
  @operand = operand
  @transformation = transformation
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Method Details

#eachObject



30
31
32
33
34
35
36
# File 'lib/bmg/operator/transform.rb', line 30

def each
  return to_enum unless block_given?
  t = transformer
  @operand.each do |tuple|
    yield t.call(tuple)
  end
end

#to_astObject



38
39
40
# File 'lib/bmg/operator/transform.rb', line 38

def to_ast
  [ :transform, operand.to_ast, transformation.dup ]
end