1
0

Updated Formula::calculate to use FormulaBuilder

This commit is contained in:
cryptogopher
2020-01-27 00:59:33 +01:00
parent 98207fc980
commit df8703ba3c
4 changed files with 44 additions and 22 deletions

View File

@@ -29,6 +29,24 @@ 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
def movable?(direction)
@@ -47,14 +65,6 @@ class Quantity < ActiveRecord::Base
end
end
def formula_quantities
Formula.new(self.project, self.formula).get_quantities
end
def calculate(inputs)
Formula.new(self.project, self.formula).calculate(inputs)
end
def self.filter(project, filters)
quantities = all

View File

@@ -43,7 +43,7 @@
</td>
<td class="domain"><%= q.domain %></td>
<td class="description"><%= q.description %></td>
<td class="formula"><%= checked_image q.formula.present? %></td>
<td class="formula"><%= checked_image q.formula? %></td>
<td class="action unwrappable">
<%= link_to l(:button_edit), edit_quantity_path(q), {
remote: true,