class Axiom::Algebra::Summarization

Summarize a relation by specific attributes

Attributes

summarize_per[R]

The relation to summarize with

@return [Relation]

@api private

summarizers[R]

The summarizers for the relation

@return [Hash]

@api private

Public Class Methods

new(operand, summarize_per, _summarizers) click to toggle source

Instantiate a new Summarization

@example

summarization = Summarization.new(operand, summarize_per, summarizers)

@param [Relation] operand

the relation to summarize

@param [Relation] summarize_per

the relation to summarize with

@param [#to_hash] _summarizers

the summarizers to add

@return [Summarization]

@api public

Calls superclass method Axiom::Relation::Operation::Unary::new
# File lib/axiom/algebra/summarization.rb, line 40
def self.new(operand, summarize_per, _summarizers)
  assert_subset_headers(operand, summarize_per)
  super
end
new(operand, summarize_per, summarizers) click to toggle source

Initialize a Summarization

@param [Relation] operand

the relation to summarize

@param [Relation] summarize_per

the relation to summarize with

@param [#to_hash] summarizers

the summarizers to add

@return [undefined]

@api private

Calls superclass method Axiom::Relation::Operation::Unary::new
# File lib/axiom/algebra/summarization.rb, line 76
def initialize(operand, summarize_per, summarizers)
  super(operand)
  @summarize_per = summarize_per
  @summarizers   = summarizers
  @header        = @summarize_per.header | @summarizers.keys
end

Private Class Methods

assert_subset_headers(operand, summarize_per) click to toggle source

Assert the summarize_per header is a subset of the operand header

@param [Relation] operand @param [Relation] summarize_per

@return [undefined]

@raise [InvalidHeaderError]

raised if the summarize_per header is not a subset of the operand header

@api private

# File lib/axiom/algebra/summarization.rb, line 56
def self.assert_subset_headers(operand, summarize_per)
  unless summarize_per.header.to_set.proper_subset?(operand.header.to_set)
    fail InvalidHeaderError, 'the summarize_per header must be a proper subset of the operand header'
  end
end

Public Instance Methods

delete(*) click to toggle source

Raise an exception when deleting from a Summarization

@example

summarization.delete(other)  # => ImmutableRelationError raised

@return [undefined]

@raise [ImmutableRelationError]

raised when deleting from the summarization

@api public

# File lib/axiom/algebra/summarization.rb, line 129
def delete(*)
  fail ImmutableRelationError, 'deleting from a summarization is impossible'
end
each() { |tuple| ... } click to toggle source

Iterate over each tuple in the set

@example

summarization = Summarization.new(self, relation, context.functions)
summarization.each { |tuple| ... }

@yield [tuple]

@yieldparam [Tuple] tuple

each tuple in the set

@return [self]

@api public

# File lib/axiom/algebra/summarization.rb, line 97
def each
  return to_enum unless block_given?
  summarize_per.extend(summaries).each { |tuple| yield tuple }
  self
end
insert(*) click to toggle source

Raise an exception when inserting into a Summarization

@example

summarization.insert(other)  # => ImmutableRelationError raised

@return [undefined]

@raise [ImmutableRelationError]

raised when inserting into the summarization

@api public

# File lib/axiom/algebra/summarization.rb, line 114
def insert(*)
  fail ImmutableRelationError, 'inserting into a summarization is impossible'
end

Private Instance Methods

default_summaries() click to toggle source

Return the default summaries

@return [Summaries]

@api private

# File lib/axiom/algebra/summarization.rb, line 151
def default_summaries
  Summaries.new(summarize_per.header, summarizers)
end
summaries() click to toggle source

Return the current summaries

@return [Hash]

@api private

# File lib/axiom/algebra/summarization.rb, line 140
def summaries
  summaries = default_summaries
  operand.each { |tuple| summaries.summarize_by(tuple) }
  summaries.to_hash
end