Skip to content

Commit

Permalink
Fix FR Nutriscore when negative points ≥11
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Jun 7, 2022
1 parent e0e0b56 commit eec3947
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/nutriscore/fr/positive_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def proteins
end
end
end

def score_without_proteins
(self.class.nutrient_keys - [:proteins]).map(&method(:public_send)).compact.reduce(&:+)
end
end
end
end
16 changes: 16 additions & 0 deletions spec/nutriscore/fr/specific_score_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,20 @@
its(:score) { is_expected.to eq(-2) }
its(:score_class) { is_expected.to eq 'A' }
end

# https://www.willys.se/produkt/Kottbullar-Mammas-100084061_ST
# a Questionmark researcher manually computed the scores
context 'Köttbullar Mammas (score without proteins)' do
let(:nutrients) {{
energy: 900, # kJ/100g
fat_saturated: 6, # g/100g
sugar: 1, # g/100g
fvnp: 0..40, # g/100g (= weight-%) - manual estimate
fibres: 0.3, # g/100g
proteins: 13, # g/100g
sodium: 0.64, # g/100g
}}
its(:score) { is_expected.to eq(14) }
its(:score_class) { is_expected.to eq 'D' }
end
end

0 comments on commit eec3947

Please sign in to comment.