Class: Reporter::Field::FormulaField

Inherits:
Base
  • Object
show all
Defined in:
lib/reporter/field/formula_field.rb

Instance Method Summary collapse

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, options = {}
	super structure, alias_name
	@formula = Reporter::Formula.new formula
	@options = 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, calculation_options
	required_terms = {}
	formula.term_list.each do |term|
		required_terms[term] = nil
		required_terms[term] = calculation_options[:row][term].value if calculation_options[:row] and term != name
	end
	value = formula.call(required_terms)

	Reporter::Value.new(name, options[:name], value, nil, options[:description], options[:source_link])
end