module Axiom::Algebra::Summarization::Methods
Public Instance Methods
summarize(summarize_with = TABLE_DEE, *args, &block)
click to toggle source
Return a summarized relation
@example with no arguments
summarization = relation.summarize do |context| context.add(:count, context[:id].count) end
@example with a relation
summarization = relation.summarize(relation.project([:name])) do |context| context.add(:count, context[:id].count) end
@example with a header
summarization = relation.summarize([:name]) do |context| context.add(:count, context[:id].count) end
@example with summarizers
summarization = relation.summarize([:name], summarizers)
@param [Relation, Header, to_ary] summarize_with
@yield [function]
Evaluate a summarization function
@yieldparam [Evaluator::Context] context
the context to evaluate the function within
@return [Summarization]
@api public
# File lib/axiom/algebra/summarization.rb, line 188 def summarize(summarize_with = TABLE_DEE, *args, &block) summarize_per = coerce_to_relation(summarize_with) summarizers = coerce_to_summarizers(summarize_per, *args, &block) Summarization.new(self, summarize_per, summarizers) end
Private Instance Methods
coerce_to_relation(summarize_with)
click to toggle source
Coerce the argument into a Relation
@param [Relation, Header, to_ary] summarize_with
the relation, header or attributes to summarize with
@return [Relation]
@api private
# File lib/axiom/algebra/summarization.rb, line 204 def coerce_to_relation(summarize_with) if summarize_with.kind_of?(Relation) summarize_with else project(summarize_with) end end
coerce_to_summarizers(summarize_per, summarizers = Undefined, &block)
click to toggle source
Coerce the arguments and block into summarizers
@param [#header] summarize_per
the Relation to summarize with
@param [Hash] summarizers
optional summarizers
@yield [function]
Evaluate a summarization function
@yieldparam [Evaluator::Context] context
the context to evaluate the function within
@return [#to_hash]
@api private
# File lib/axiom/algebra/summarization.rb, line 228 def coerce_to_summarizers(summarize_per, summarizers = Undefined, &block) if summarizers.equal?(Undefined) (header - summarize_per.header).context(&block).functions else summarizers end end