Class: Bmg::Operator::Rename
- Inherits:
-
Object
- Object
- Bmg::Operator::Rename
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/rename.rb
Overview
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.
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #_count ⇒ Object
- #delete(predicate = Predicate.tautology) ⇒ Object
- #each ⇒ Object
-
#initialize(type, operand, renaming) ⇒ Rename
constructor
A new instance of Rename.
- #insert(arg) ⇒ Object
- #to_ast ⇒ Object
- #update(arg, predicate = Predicate.tautology) ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
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, #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, renaming) ⇒ Rename
Returns a new instance of Rename.
19 20 21 22 23 |
# File 'lib/bmg/operator/rename.rb', line 19 def initialize(type, operand, renaming) @type = type @operand = operand @renaming = renaming end |
Instance Method Details
#_count ⇒ Object
67 68 69 |
# File 'lib/bmg/operator/rename.rb', line 67 def _count operand._count end |
#delete(predicate = Predicate.tautology) ⇒ Object
57 58 59 |
# File 'lib/bmg/operator/rename.rb', line 57 def delete(predicate = Predicate.tautology) operand.delete(predicate) end |
#each ⇒ Object
31 32 33 34 35 36 |
# 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) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
61 62 63 |
# File 'lib/bmg/operator/rename.rb', line 61 def to_ast [ :rename, operand.to_ast, renaming.dup ] end |
#update(arg, predicate = Predicate.tautology) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/bmg/operator/rename.rb', line 48 def update(arg, predicate = Predicate.tautology) case arg when Hash operand.update(rename_tuple(arg, reverse_renaming), predicate) else super end end |