From b6c453c37cb75c97fd029ed9c1f5829fd09658e8 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Thu, 7 Nov 2019 16:10:15 +0100 Subject: [PATCH] Further optimized nutrient calculation defaults --- app/models/ingredient.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/ingredient.rb b/app/models/ingredient.rb index 56e533e..4d92c05 100644 --- a/app/models/ingredient.rb +++ b/app/models/ingredient.rb @@ -55,7 +55,7 @@ class Ingredient < ActiveRecord::Base # quantity not computable (no formula) or not requiring calculation/computed if q.formula.blank? || (nutrients[q.name].length == ingredients.count) - completed_q[q.name] = nutrients.delete(q.name) || {} + completed_q[q.name] = nutrients.delete(q.name) { {} } next end @@ -73,10 +73,10 @@ class Ingredient < ActiveRecord::Base [ i, input_q.map do |i_q| - nutrient_data = (completed_q[i_q.name] || nutrients[i_q.name])[i.id] # FIXME: result for computation with nil values (substituted with 0s) # should be marked as not precise - [i_q.name, (nutrient_data || [0, nil])[0]] + nutrient_data = completed_q[i_q.name][i.id] || [0, nil] + [i_q.name, nutrient_data[0]] end.to_h ] end