Class: Bmg::Operator::Allbut
- Inherits:
-
Object
- Object
- Bmg::Operator::Allbut
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/allbut.rb
Overview
Allbut operator.
Projects operand’s tuples on all but given attributes, that is, removes attributes in the list. The operator takes care of removing duplicates.
Example:
[{ a: 1, b: 2 }] allbut [:b] => [{ a: 1 }]
All attributes in the butlist SHOULD be existing attributes of the input tuples.
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #delete(predicate = Predicate.tautology) ⇒ Object
- #each ⇒ Object
-
#initialize(type, operand, butlist) ⇒ Allbut
constructor
A new instance of Allbut.
- #insert(arg) ⇒ Object
- #to_ast ⇒ Object
- #update(tuple, predicate = Predicate.tautology) ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#_count, #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, butlist) ⇒ Allbut
Returns a new instance of Allbut.
20 21 22 23 24 |
# File 'lib/bmg/operator/allbut.rb', line 20 def initialize(type, operand, butlist) @type = type @operand = operand @butlist = butlist end |
Instance Method Details
#delete(predicate = Predicate.tautology) ⇒ Object
57 58 59 |
# File 'lib/bmg/operator/allbut.rb', line 57 def delete(predicate = Predicate.tautology) operand.delete(predicate) end |
#each ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bmg/operator/allbut.rb', line 32 def each return to_enum unless block_given? seen = {} @operand.each do |tuple| allbuted = tuple_allbut(tuple) unless seen.has_key?(allbuted) yield(allbuted) seen[allbuted] = true end end end |
#insert(arg) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/bmg/operator/allbut.rb', line 44 def insert(arg) case arg when Hash then operand.insert(valid_tuple!(arg)) when Enumerable then operand.insert(arg.map{|t| valid_tuple!(t) }) else super end end |
#to_ast ⇒ Object
61 62 63 |
# File 'lib/bmg/operator/allbut.rb', line 61 def to_ast [:allbut, operand.to_ast, butlist.dup] end |
#update(tuple, predicate = Predicate.tautology) ⇒ Object
53 54 55 |
# File 'lib/bmg/operator/allbut.rb', line 53 def update(tuple, predicate = Predicate.tautology) operand.update(valid_tuple!(tuple), predicate) end |