Class: Goldmine::Rollup

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/goldmine/rollup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pivot_result, block) ⇒ Rollup

Returns a new instance of Rollup.



12
13
14
15
16
17
# 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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/goldmine/rollup.rb', line 10

def name
  @name
end

#procObject (readonly)

Returns the value of attribute proc.



10
11
12
# File 'lib/goldmine/rollup.rb', line 10

def proc
  @proc
end

Instance Method Details

#result(cache: false) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



19
20
21
# File 'lib/goldmine/rollup.rb', line 19

def rollup(name, &block)
  self.class.new(name, pivot_result, block)
end