Sha256: a555eea3438edadfda9a48f47adc45682950b70d1a684c229480630d622d1ec6

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

# encoding: utf-8

module Axiom
  module Algebra
    class Summarization

      # The summary for an aggregate function grouped by tuple
      class Summary

        # Initialize a Summary
        #
        # @param [#call] summarizer
        #
        # @return [undefined]
        #
        # @api private
        def initialize(summarizer)
          @summarizer = summarizer
          @summary    = Hash.new(summary_default)
        end

        # Summarize the aggregate function by a tuple
        #
        # @example
        #   summary = summary.summarize_by(projection, tuple)
        #
        # @param [Tuple] projection
        #   the tuple projection to summarize the results by
        # @param [Tuple] tuple
        #   the tuple to execute the aggregate function with
        #
        # @return [self]
        #
        # @api public
        def summarize_by(projection, tuple)
          @summary[projection] = @summarizer.call(@summary[projection], tuple)
          self
        end

        # Return the finalized summary for a tuple
        #
        # @example
        #   object = summary.call(tuple)
        #
        # @param [Tuple] tuple
        #
        # @return [Object]
        #
        # @api public
        def call(tuple)
          summary_finalize(@summary[tuple])
        end

      private

        # Return the summary default
        #
        # @return [Object]
        #
        # @api private
        def summary_default
          @summarizer.default if @summarizer.respond_to?(:default)
        end

        # Finalize the summary value if possible
        #
        # @param [Object] value
        #
        # @return [Object]
        #
        # @api private
        def summary_finalize(value)
          if @summarizer.respond_to?(:finalize)
            @summarizer.finalize(value)
          else
            value
          end
        end

      end # class Summary
    end # class Summarization
  end # module Algebra
end # module Axiom

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
axiom-0.2.0 lib/axiom/algebra/summarization/summary.rb
axiom-0.1.1 lib/axiom/algebra/summarization/summary.rb
axiom-0.1.0 lib/axiom/algebra/summarization/summary.rb