Class: Nutriscore::FR::PositiveScore

Inherits:
Common::Score show all
Defined in:
lib/nutriscore/fr/positive_score.rb

Instance Attribute Summary

Attributes inherited from Common::Score

#nutrients

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Score

#initialize, #inspect, #score

Constructor Details

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

Class Method Details

.nutrient_keysObject



7
8
9
# File 'lib/nutriscore/fr/positive_score.rb', line 7

def self.nutrient_keys
  [:fvnp, :fibres, :proteins]
end

Instance Method Details

#fibresObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nutriscore/fr/positive_score.rb', line 21

def fibres
  score_value(@nutrients.fibres, 0..5) do |v|
    if    v > 4.7 then 5
    elsif v > 3.7 then 4
    elsif v > 2.8 then 3
    elsif v > 1.9 then 2
    elsif v > 0.9 then 1
    else               0
    end
  end
end

#fvnpObject



11
12
13
14
15
16
17
18
19
# File 'lib/nutriscore/fr/positive_score.rb', line 11

def fvnp
  score_value(@nutrients.fvnp, 0..5) do |v|
    if    v > 80 then 5
    elsif v > 60 then 2
    elsif v > 40 then 1
    else              0
    end
  end
end

#proteinsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/nutriscore/fr/positive_score.rb', line 33

def proteins
  score_value(@nutrients.proteins, 0..5) do |v|
    if    v > 8.0 then 5
    elsif v > 6.4 then 4
    elsif v > 4.8 then 3
    elsif v > 3.2 then 2
    elsif v > 1.6 then 1
    else               0
    end
  end
end

#score_without_proteinsObject



45
46
47
# File 'lib/nutriscore/fr/positive_score.rb', line 45

def score_without_proteins
  (self.class.nutrient_keys - [:proteins]).map(&method(:public_send)).compact.reduce(&:+)
end