class Axiom::Algebra::Extension
Extend a relation to include calculated attributes
Attributes
The extensions for the relation
@return [Hash]
@api private
Public Class Methods
Initialize an Extension
@param [Relation] operand
the relation to extend
@param [Hash] extensions
the extensions to add
@return [undefined]
@api private
Axiom::Relation::Operation::Unary::new
# File lib/axiom/algebra/extension.rb, line 28 def initialize(operand, extensions) super(operand) keys = extensions.keys @header = @header.extend(keys) @extensions = Hash[@header.project(keys).zip(extensions.values)] end
Public Instance Methods
Delete a relation from the Extension
The other relation must be a matching extension.
@example
new_relation = extension.delete(other)
@param [Relation] other
@return [Extension]
@raise [ExtensionMismatchError]
raised when deleting with a mismatching extension
@api public
# File lib/axiom/algebra/extension.rb, line 91 def delete(other) assert_matching_extensions(other, DELETED) operand.delete(other.operand).extend(extensions) end
Iterate over each tuple in the set
@example
extension = Extension.new(operand, extensions) extension.each { |tuple| ... }
@yield [tuple]
@yieldparam [Tuple] tuple
each tuple in the set
@return [self]
@api public
# File lib/axiom/algebra/extension.rb, line 49 def each return to_enum unless block_given? extensions = self.extensions.values operand.each { |operand_tuple| yield operand_tuple.extend(header, extensions) } self end
Insert a relation into the Extension
The other relation must be a matching extension.
@example
new_relation = extension.insert(other)
@param [Relation] other
@return [Extension]
@raise [ExtensionMismatchError]
raised when inserting with a mismatching extension
@api public
# File lib/axiom/algebra/extension.rb, line 71 def insert(other) assert_matching_extensions(other, INSERTED) operand.insert(other.operand).extend(extensions) end
Private Instance Methods
Assert that the other relation has matching extensions
@param [Relation] other
@param [String] event
@return [undefined]
@raise [ExtensionMismatchError]
raised when inserting a relation does not have matching extensions
@api private
# File lib/axiom/algebra/extension.rb, line 110 def assert_matching_extensions(other, event) unless other.kind_of?(self.class) && extensions.eql?(other.extensions) fail ExtensionMismatchError, "other relation must have matching extensions to be #{event}" end end