class Goldmine::Rollup

Attributes

name[R]
pivot_result[R]
proc[R]

Public Class Methods

new(name, pivot_result, block) click to toggle source
# File lib/goldmine/rollup.rb, line 12
def initialize(name, pivot_result, block)
  @name = name
  @pivot_result = pivot_result
  @proc = block
  pivot_result.rollups << self
end

Public Instance Methods

result(cache: false) click to toggle source
# File lib/goldmine/rollup.rb, line 23
def result(cache: false)
  perform_caching = cache || pivot.miner.cache
  RollupResult.new.tap do |rollup_result|
    pivot_result.each do |pivot_key, pivoted_list|
      stash = {} if perform_caching
      pivot_result.rollups.each do |rollup|
        Array.new(2).tap do |computed_value|
          key = rollup.name
          value = RollupCleanRoom.new(key, stash).rollup(pivoted_list, &rollup.proc) if perform_caching
          value ||= rollup.proc.call(pivoted_list)
          computed_value[0] = key
          computed_value[1] = value
          (rollup_result[pivot_key] ||= []) << computed_value
        end
      end
    end
  end
end
rollup(name, &block) click to toggle source
# File lib/goldmine/rollup.rb, line 19
def rollup(name, &block)
  self.class.new(name, pivot_result, block)
end