Class: Nutriscore::FR::DrinksScore
Overview
Instance Attribute Summary
#nutrients
Class Method Summary
collapse
Instance Method Summary
collapse
#score_class
#initialize, #inspect, #score
Class Method Details
.nutrient_keys ⇒ Object
10
11
12
|
# File 'lib/nutriscore/fr/drinks_score.rb', line 10
def self.nutrient_keys
[:energy, :sugar, :fvnp]
end
|
Instance Method Details
#energy ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/nutriscore/fr/drinks_score.rb', line 14
def energy
score_value(@nutrients.energy, 0..10) do |v|
if v == 0 then 0
elsif v <= 30 then 1
elsif v <= 60 then 2
elsif v <= 90 then 3
elsif v <= 120 then 4
elsif v <= 150 then 5
elsif v <= 180 then 6
elsif v <= 210 then 7
elsif v <= 240 then 8
elsif v <= 270 then 9
else 10
end
end
end
|
#fvnp ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/nutriscore/fr/drinks_score.rb', line 48
def fvnp
score_value(@nutrients.fvnp, 0..10) do |v|
if v > 80 then 10
elsif v > 60 then 4
elsif v > 40 then 2
else 0
end
end
end
|
#sugar ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/nutriscore/fr/drinks_score.rb', line 31
def sugar
score_value(@nutrients.sugar, 0..10) do |v|
if v == 0 then 0
elsif v < 1.5 then 1
elsif v < 3 then 2
elsif v < 4.5 then 3
elsif v < 6 then 4
elsif v < 7.5 then 5
elsif v < 9 then 6
elsif v < 10.5 then 7
elsif v < 12 then 8
elsif v < 13.5 then 9
else 10
end
end
end
|