Class: Repor::Aggregators::BaseAggregator
- Inherits:
-
Object
- Object
- Repor::Aggregators::BaseAggregator
- Defined in:
- lib/repor/aggregators/base_aggregator.rb
Direct Known Subclasses
ArrayAggregator, AvgAggregator, CountAggregator, MaxAggregator, MinAggregator, SumAggregator
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
-
#aggregate(groups) ⇒ Object
This is the method called by Repor::Report.
-
#initialize(name, report, opts = {}) ⇒ BaseAggregator
constructor
A new instance of BaseAggregator.
Constructor Details
#initialize(name, report, opts = {}) ⇒ BaseAggregator
Returns a new instance of BaseAggregator.
6 7 8 9 10 |
# File 'lib/repor/aggregators/base_aggregator.rb', line 6 def initialize(name, report, opts={}) @name = name @report = report @opts = opts end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/repor/aggregators/base_aggregator.rb', line 4 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/repor/aggregators/base_aggregator.rb', line 4 def opts @opts end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
4 5 6 |
# File 'lib/repor/aggregators/base_aggregator.rb', line 4 def report @report end |
Instance Method Details
#aggregate(groups) ⇒ Object
This is the method called by Repor::Report. It should return a hash of array keys (of grouper values) mapped to aggregation values.
14 15 16 17 18 19 20 21 |
# File 'lib/repor/aggregators/base_aggregator.rb', line 14 def aggregate(groups) query = aggregation(relate(groups)) result = ActiveRecord::Base.connection.select_all(query) result.cast_values.each_with_object(Hash.new(default_y_value)) do |values, h| row = result.columns.zip(values).to_h h[x_value_of(row)] = y_value_of(row) end end |