Class: Reporter::Field::FormulaField
- Inherits:
-
Base
- Object
- Base
- Reporter::Field::FormulaField
- Defined in:
- lib/reporter/field/formula_field.rb
Instance Method Summary collapse
- #calculate_value(data_source, calculation_options) ⇒ Object
-
#initialize(structure, alias_name, formula, options = {}) ⇒ FormulaField
constructor
A new instance of FormulaField.
Constructor Details
#initialize(structure, alias_name, formula, options = {}) ⇒ FormulaField
Returns a new instance of FormulaField.
3 4 5 6 7 |
# File 'lib/reporter/field/formula_field.rb', line 3 def initialize structure, alias_name, formula, = {} super structure, alias_name @formula = Reporter::Formula.new formula @options = end |
Instance Method Details
#calculate_value(data_source, calculation_options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/reporter/field/formula_field.rb', line 9 def calculate_value data_source, required_terms = {} formula.term_list.each do |term| required_terms[term] = nil required_terms[term] = [:row][term].value if [:row] and term != name end value = formula.call(required_terms) Reporter::Value.new(name, [:name], value, nil, [:description], [:source_link]) end |