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, options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
# File 'lib/active_reporter/aggregator/base.rb', line 8

def initialize(name, report, options = {})
  @name = name
  @report = report
  @options = options
  validate_params!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/active_reporter/aggregator/base.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/active_reporter/aggregator/base.rb', line 6

def options
  @options
end

#reportObject (readonly)

Returns the value of attribute report.



6
7
8
# File 'lib/active_reporter/aggregator/base.rb', line 6

def report
  @report
end

Instance Method Details

#aggregate(groups) ⇒ Object



23
24
25
# File 'lib/active_reporter/aggregator/base.rb', line 23

def aggregate(groups)
  relate(groups).select("#{function} AS #{sql_value_name}")
end

#default_valueObject



19
20
21
# File 'lib/active_reporter/aggregator/base.rb', line 19

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

#sql_value_nameObject



15
16
17
# File 'lib/active_reporter/aggregator/base.rb', line 15

def sql_value_name
  "_report_aggregator_#{name}"
end