Class: Reporter::Field::CalculationField
- Inherits:
-
Base
- Object
- Base
- Reporter::Field::CalculationField
- Defined in:
- lib/reporter/field/calculation_field.rb
Direct Known Subclasses
Instance Method Summary collapse
- #calculate_value(data_source, calculation_options) ⇒ Object
-
#initialize(structure, alias_name, data_source, calculation, column, options = {}, &block) ⇒ CalculationField
constructor
A new instance of CalculationField.
- #preload_for_period(data_source, calculation_options, period, filter, scope) ⇒ Object
Constructor Details
#initialize(structure, alias_name, data_source, calculation, column, options = {}, &block) ⇒ CalculationField
Returns a new instance of CalculationField.
3 4 5 6 7 8 9 10 |
# File 'lib/reporter/field/calculation_field.rb', line 3 def initialize structure, alias_name, data_source, calculation, column, = {}, &block super structure, alias_name @source = data_source @column = column @options = @calculation = calculation @calculation_block = block if block_given? end |
Instance Method Details
#calculate_value(data_source, calculation_options) ⇒ Object
12 13 14 15 16 |
# File 'lib/reporter/field/calculation_field.rb', line 12 def calculate_value data_source, source = data_source.get(@source) value = source.calculate @calculation, @column, , &calculation_block Reporter::Value.new(name, [:name], value, nil, [:description], [:source_link]) end |
#preload_for_period(data_source, calculation_options, period, filter, scope) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/reporter/field/calculation_field.rb', line 18 def preload_for_period data_source, , period, filter, scope source = data_source.get(@source) values = source.calculate_for_period @calculation, period, filter, scope, @column, , &calculation_block results = {} values.each do |r| val = r.delete :value results[r] = Reporter::Value.new(name, [:name], val, nil, [:description], [:source_link]) end results end |