class Bmg::Operator::Rename
Rename
operator.
Rename
some attribute of input tuples, according to a renaming Hash.
Example:
[{ a: 1, b: 2 }] rename {:b => :c} => [{ a: 1, c: 2 }]
Keys
of the renaming Hash SHOULD be existing attributes of the input tuples. Values of the renaming Hash SHOULD NOT be existing attributes of the input tuples.
Attributes
renaming[R]
Public Class Methods
new(type, operand, renaming)
click to toggle source
# File lib/bmg/operator/rename.rb, line 19 def initialize(type, operand, renaming) @type = type @operand = operand @renaming = renaming end
Public Instance Methods
delete()
click to toggle source
# File lib/bmg/operator/rename.rb, line 56 def delete operand.delete end
each() { |rename_tuple(tuple, renaming)| ... }
click to toggle source
# File lib/bmg/operator/rename.rb, line 31 def each return to_enum unless block_given? @operand.each do |tuple| yield rename_tuple(tuple, renaming) end end
insert(arg)
click to toggle source
Calls superclass method
# File lib/bmg/operator/rename.rb, line 38 def insert(arg) case arg when Hash then operand.insert(rename_tuple(arg, reverse_renaming)) when Relation then operand.insert(arg.rename(reverse_renaming)) when Enumerable then operand.insert(arg.map{|t| rename_tuple(t, reverse_renaming) }) else super end end
to_ast()
click to toggle source
# File lib/bmg/operator/rename.rb, line 60 def to_ast [ :rename, operand.to_ast, renaming.dup ] end
update(arg)
click to toggle source
Calls superclass method
# File lib/bmg/operator/rename.rb, line 48 def update(arg) case arg when Hash then operand.update(rename_tuple(arg, reverse_renaming)) else super end end