Class: ActiveReporter::Aggregator::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/active_reporter/aggregator/base.rb', line 4

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/active_reporter/aggregator/base.rb', line 4

def opts
  @opts
end

#reportObject (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_valueObject



17
18
19
# File 'lib/active_reporter/aggregator/base.rb', line 17

def default_value
  opts.fetch(:default_value, nil)
end

#sql_value_nameObject



13
14
15
# File 'lib/active_reporter/aggregator/base.rb', line 13

def sql_value_name
  "_report_aggregator_#{name}"
end