Class: ActiveReporter::Aggregator::Base
- Inherits:
-
Object
- Object
- ActiveReporter::Aggregator::Base
- Defined in:
- lib/active_reporter/aggregator/base.rb
Direct Known Subclasses
Array, Average, Count, Max, Min, Ratio, Sum, Calculator::Base, Tracker::Base
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
- #default_value ⇒ Object
-
#initialize(name, report, opts = {}) ⇒ Base
constructor
A new instance of Base.
- #sql_value_name ⇒ Object
Constructor Details
#initialize(name, report, opts = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/active_reporter/aggregator/base.rb', line 6 def initialize(name, report, opts={}) @name = name @report = report @opts = opts validate_params! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/active_reporter/aggregator/base.rb', line 4 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
4 5 6 |
# File 'lib/active_reporter/aggregator/base.rb', line 4 def opts @opts end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
4 5 6 |
# File 'lib/active_reporter/aggregator/base.rb', line 4 def report @report end |
Instance Method Details
#aggregate(groups) ⇒ Object
21 22 23 |
# File 'lib/active_reporter/aggregator/base.rb', line 21 def aggregate(groups) relate(groups).select("#{function} AS #{sql_value_name}") end |
#default_value ⇒ Object
17 18 19 |
# File 'lib/active_reporter/aggregator/base.rb', line 17 def default_value opts.fetch(:default_value, nil) end |
#sql_value_name ⇒ Object
13 14 15 |
# File 'lib/active_reporter/aggregator/base.rb', line 13 def sql_value_name "_report_aggregator_#{name}" end |