1
0

Formula can contain model method calls

This commit is contained in:
cryptogopher
2020-05-05 01:52:34 +02:00
parent 36a2e7bcbe
commit 8749710330
4 changed files with 39 additions and 39 deletions

View File

@@ -39,12 +39,16 @@ class Formula < ActiveRecord::Base
private
def parse
parser = FormulaBuilder.new(self.code)
d_methods = ['abs', 'nil?']
q_methods = Hash.new(['all', 'lastBefore'])
q_methods['Meal'] = Meal.attribute_names
parser = FormulaBuilder.new(self.code, d_methods: d_methods, q_methods: q_methods)
identifiers, parts = parser.parse
errors = parser.errors
quantities = Quantity.where(project: self.quantity.project, name: identifiers)
(identifiers - quantities.map(&:name)).each do |q|
(identifiers - quantities.map(&:name) - quantity_m.keys).each do |q|
errors << [:unknown_quantity, {quantity: q}]
end