class Axiom::Algebra::Product
The cartesian product between relations
Public Class Methods
new(left, right)
click to toggle source
Instantiate a new Product
@example
product = Product.new(left, right)
@param [Relation] left @param [Relation] right
@return [Join]
@api public
Calls superclass method
# File lib/axiom/algebra/product.rb, line 21 def self.new(left, right) assert_disjointed_headers(left, right) super end
Private Class Methods
assert_disjointed_headers(left, right)
click to toggle source
Assert the headers do not have common attributes
@param [Relation] left @param [Relation] right
@return [undefined]
@raise [InvalidHeaderError]
raised if there are common attributes between the headers
@api private
# File lib/axiom/algebra/product.rb, line 37 def self.assert_disjointed_headers(left, right) if (left.header & right.header).any? fail InvalidHeaderError, 'the headers must be disjointed' end end
Public Instance Methods
delete(*)
click to toggle source
Raise an exception when deleting from the Product
@example
product.delete(other) # => ImmutableRelationError raised
@return [undefined]
@raise [ImmutableRelationError]
raised when deleting from the product
@api public
# File lib/axiom/algebra/product.rb, line 94 def delete(*) fail ImmutableRelationError, 'deleting from a product is impossible' end
each(&block)
click to toggle source
Iterate over each tuple in the set
@example
product = Product.new(left, right) product.each { |tuple| ... }
@yield [tuple]
@yieldparam [Tuple] tuple
each tuple in the set
@return [self]
@api public
# File lib/axiom/algebra/product.rb, line 59 def each(&block) return to_enum unless block_given? util = Relation::Operation::Combination left.each do |left_tuple| util.combine_tuples(header, left_tuple, right, &block) end self end
insert(*)
click to toggle source
Raise an exception when inserting into the Product
@example
product.insert(other) # => ImmutableRelationError raised
@return [undefined]
@raise [ImmutableRelationError]
raised when inserting into the product
@api public
# File lib/axiom/algebra/product.rb, line 79 def insert(*) fail ImmutableRelationError, 'inserting into a product is impossible' end