Sha256: 20a3d965f2661b13ddd5342f4995d180ad44683dbf43d20efccbecd9ec28be6b

Contents?: true

Size: 673 Bytes

Versions: 5

Compression:

Stored size: 673 Bytes

Contents

class Reporter::Field::FormulaField < Reporter::Field::Base

	def initialize structure, alias_name, formula, options = {}
		super structure, alias_name
		@formula = Reporter::Formula.new formula
		@options = options
	end

	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

	private

	attr_reader :options, :formula

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reporter-0.0.5 lib/reporter/field/formula_field.rb
reporter-0.0.4 lib/reporter/field/formula_field.rb
reporter-0.0.3 lib/reporter/field/formula_field.rb
reporter-0.0.2 lib/reporter/field/formula_field.rb
reporter-0.0.1 lib/reporter/field/formula_field.rb