Class: Axiom::Algebra::Extension

Inherits:
Relation
  • Object
show all
Includes:
Relation::Operation::Unary
Defined in:
lib/axiom/algebra/extension.rb

Overview

Extend a relation to include calculated attributes

Defined Under Namespace

Modules: Methods

Instance Attribute Summary collapse

Attributes included from Operation::Unary

#operand

Attributes inherited from Relation

#header

Instance Method Summary collapse

Methods inherited from Relation

#==, #[], #directions, #empty?, #include?, #materialize, #materialized?, new, #replace

Methods included from Visitable

#accept

Constructor Details

#initialize(operand, extensions) ⇒ 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 an Extension

Parameters:

  • operand (Relation)

    the relation to extend

  • extensions (Hash)

    the extensions to add



28
29
30
31
32
33
# 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

Instance Attribute Details

#extensionsHash (readonly)

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.

The extensions for the relation

Returns:

  • (Hash)


16
17
18
# File 'lib/axiom/algebra/extension.rb', line 16

def extensions
  @extensions
end

Instance Method Details

#delete(other) ⇒ Extension

Delete a relation from the Extension

The other relation must be a matching extension.

Examples:

new_relation = extension.delete(other)

Parameters:

Returns:

Raises:



91
92
93
94
# File 'lib/axiom/algebra/extension.rb', line 91

def delete(other)
  assert_matching_extensions(other, DELETED)
  operand.delete(other.operand).extend(extensions)
end

#each {|tuple| ... } ⇒ self

Iterate over each tuple in the set

Examples:

extension = Extension.new(operand, extensions)
extension.each { |tuple| ... }

Yields:

  • (tuple)

Yield Parameters:

  • tuple (Tuple)

    each tuple in the set

Returns:

  • (self)


49
50
51
52
53
54
# 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(other) ⇒ Extension

Insert a relation into the Extension

The other relation must be a matching extension.

Examples:

new_relation = extension.insert(other)

Parameters:

Returns:

Raises:



71
72
73
74
# File 'lib/axiom/algebra/extension.rb', line 71

def insert(other)
  assert_matching_extensions(other, INSERTED)
  operand.insert(other.operand).extend(extensions)
end