Class: Axiom::Algebra::Projection
- Includes:
- Relation::Operation::Unary
- Defined in:
- lib/axiom/algebra/projection.rb
Overview
Specify only specific attributes to keep in the relation
Defined Under Namespace
Modules: Methods
Instance Attribute Summary
Attributes included from Operation::Unary
Attributes inherited from Relation
Instance Method Summary collapse
-
#delete(other) ⇒ Projection
Delete a relation from the Projection.
-
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set.
-
#initialize(operand, attributes) ⇒ undefined
constructor
private
Initialize a Projection.
-
#insert(other) ⇒ Projection
Insert a relation into the Projection.
Methods inherited from Relation
#==, #[], #directions, #empty?, #include?, #materialize, #materialized?, new, #replace
Methods included from Visitable
Constructor Details
#initialize(operand, attributes) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a Projection
21 22 23 24 |
# File 'lib/axiom/algebra/projection.rb', line 21 def initialize(operand, attributes) super(operand) @header = @header.project(attributes) end |
Instance Method Details
#delete(other) ⇒ Projection
Delete a relation from the Projection
86 87 88 89 90 |
# File 'lib/axiom/algebra/projection.rb', line 86 def delete(other) other = coerce(other) assert_equivalent_headers(other) operand.delete(extend_other(other)).project(header) end |
#each {|tuple| ... } ⇒ self
Iterate over each tuple in the set
40 41 42 43 44 45 46 47 48 |
# File 'lib/axiom/algebra/projection.rb', line 40 def each return to_enum unless block_given? seen = {} operand.each do |tuple| tuple = tuple.project(header) yield seen[tuple] = tuple unless seen.key?(tuple) end self end |
#insert(other) ⇒ Projection
Insert a relation into the Projection
66 67 68 69 70 71 |
# File 'lib/axiom/algebra/projection.rb', line 66 def insert(other) other = coerce(other) assert_removed_attributes_optional assert_equivalent_headers(other) operand.insert(extend_other(other)).project(header) end |