Class: Nutriscore::FR::DrinksScore

Inherits:
Common::Score show all
Includes:
DrinksScoreClass
Defined in:
lib/nutriscore/fr/drinks_score.rb

Overview

this is for drinks

Direct Known Subclasses

MineralWaterScore

Instance Attribute Summary

Attributes inherited from Common::Score

#nutrients

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DrinksScoreClass

#score_class

Methods inherited from Common::Score

#initialize, #inspect, #score

Constructor Details

This class inherits a constructor from Nutriscore::Common::Score

Class Method Details

.nutrient_keysObject



10
11
12
# File 'lib/nutriscore/fr/drinks_score.rb', line 10

def self.nutrient_keys
  [:energy, :sugar, :fvnp]
end

Instance Method Details

#energyObject



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

#fvnpObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nutriscore/fr/drinks_score.rb', line 48

def fvnp
  # the text mentions % but here we use g/100ml
  # we'd need to either ask for %, ask for g/100g, or require a density ...
  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

#sugarObject



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