Class: Nutriscore::FR::NegativeScore
Instance Attribute Summary
#nutrients
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize, #inspect, #score
Class Method Details
.nutrient_keys ⇒ Object
7
8
9
|
# File 'lib/nutriscore/fr/negative_score.rb', line 7
def self.nutrient_keys
[:energy, :fat_saturated, :sugar, :sodium]
end
|
Instance Method Details
#energy ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/nutriscore/fr/negative_score.rb', line 11
def energy
score_value(@nutrients.energy, 0..10) do |v|
if v > 3350 then 10
elsif v > 3015 then 9
elsif v > 2680 then 8
elsif v > 2345 then 7
elsif v > 2010 then 6
elsif v > 1675 then 5
elsif v > 1340 then 4
elsif v > 1005 then 3
elsif v > 670 then 2
elsif v > 335 then 1
else 0
end
end
end
|
#fat_saturated ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/nutriscore/fr/negative_score.rb', line 28
def fat_saturated
score_value(@nutrients.fat_saturated, 0..10) do |v|
if v > 10 then 10
elsif v > 9 then 9
elsif v > 8 then 8
elsif v > 7 then 7
elsif v > 6 then 6
elsif v > 5 then 5
elsif v > 4 then 4
elsif v > 3 then 3
elsif v > 2 then 2
elsif v > 1 then 1
else 0
end
end
end
|
#sodium ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/nutriscore/fr/negative_score.rb', line 62
def sodium
score_value(@nutrients.sodium, 0..10) do |v|
v *= 1000 if v if v > 900 then 10
elsif v > 810 then 9
elsif v > 720 then 8
elsif v > 630 then 7
elsif v > 540 then 6
elsif v > 450 then 5
elsif v > 360 then 4
elsif v > 270 then 3
elsif v > 180 then 2
elsif v > 90 then 1
else 0
end
end
end
|
#sugar ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/nutriscore/fr/negative_score.rb', line 45
def sugar
score_value(@nutrients.sugar, 0..10) do |v|
if v > 45 then 10
elsif v > 40 then 9
elsif v > 36 then 8
elsif v > 31 then 7
elsif v > 27 then 6
elsif v > 22.5 then 5
elsif v > 18 then 4
elsif v > 13.5 then 3
elsif v > 9 then 2
elsif v > 4.5 then 1
else 0
end
end
end
|