Class: Bmg::Summarizer::ValueBy

Inherits:
Bmg::Summarizer show all
Defined in:
lib/bmg/summarizer/value_by.rb

Overview

ValueBy summarizer.

Example:

# direct ruby usage
Bmg::Summarizer.value_by(:qty, :by => :serie).summarize(...)

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :symbolize => false
}

Instance Attribute Summary

Attributes inherited from Bmg::Summarizer

#functor, #options

Instance Method Summary collapse

Methods inherited from Bmg::Summarizer

avg, bucketize, by_proc, collect, concat, count, distinct, distinct_count, first, #initialize, last, max, median, median_cont, median_disc, min, multiple, percentile, percentile_cont, percentile_disc, stddev, sum, summarization, #summarize, #to_summarizer_name, value_by, variance

Constructor Details

This class inherits a constructor from Bmg::Summarizer

Instance Method Details

#finalize(memo) ⇒ Object

Finalizes the computation.



33
34
35
# File 'lib/bmg/summarizer/value_by.rb', line 33

def finalize(memo)
  default_tuple.merge(memo)
end

#happens(memo, tuple) ⇒ Object

Collects the value



23
24
25
26
27
28
29
30
# File 'lib/bmg/summarizer/value_by.rb', line 23

def happens(memo, tuple)
  by = tuple[options[:by]]
  by = by.to_sym if by && options[:symbolize]
  misuse!(tuple, memo) if memo.has_key?(by)
  memo.tap{|m|
    m[by] = extract_value(tuple)
  }
end

#leastObject

Returns {} as least value.



18
19
20
# File 'lib/bmg/summarizer/value_by.rb', line 18

def least
  {}
end