1
0

Fixed calculation for indexed formulas

Delegated Quantity formula calls
This commit is contained in:
cryptogopher
2020-02-04 00:13:49 +01:00
parent df8703ba3c
commit aa26e66312
3 changed files with 21 additions and 35 deletions

View File

@@ -29,25 +29,9 @@ class Quantity < ActiveRecord::Base
if new_record?
self.domain ||= :diet
end
@formula = Formula.new(self.project, self.formula)
end
def formula=(value)
@formula = Formula.new(self.project, value)
super(value)
end
def formula_valid?
@formula.valid?
end
def formula_quantities
@formula.get_quantities
end
def calculate(inputs)
@formula.calculate(inputs)
end
delegate :valid?, :quantities, :calculate, to: :f_obj, prefix: :formula, allow_nil: true
def movable?(direction)
case direction
@@ -74,4 +58,10 @@ class Quantity < ActiveRecord::Base
quantities
end
private
def f_obj
Formula.new(self.project, self.formula) if self.formula?
end
end