class Axiom::Algebra::Summarization
Summarize a relation by specific attributes
Attributes
The relation to summarize with
@return [Relation]
@api private
The summarizers for the relation
@return [Hash]
@api private
Public Class Methods
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
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
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
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 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
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
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
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
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
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