Class: Nutriscore::UK::PositiveScore
- Inherits:
-
Common::Score
- Object
- Common::Score
- Nutriscore::UK::PositiveScore
- Defined in:
- lib/nutriscore/uk/positive_score.rb
Overview
This is called āCā-points in the documentation
Instance Attribute Summary
Attributes inherited from Common::Score
Class Method Summary collapse
Instance Method Summary collapse
- #fibres ⇒ Object
- #fvnp ⇒ Object
-
#initialize(nutrients, fibres_method: :aoac, **opts) ⇒ PositiveScore
constructor
A new instance of PositiveScore.
- #proteins ⇒ Object
- #score_without_proteins ⇒ Object
Methods inherited from Common::Score
Constructor Details
#initialize(nutrients, fibres_method: :aoac, **opts) ⇒ PositiveScore
Returns a new instance of PositiveScore.
8 9 10 11 |
# File 'lib/nutriscore/uk/positive_score.rb', line 8 def initialize(nutrients, fibres_method: :aoac, **opts) super(nutrients, **opts) @fibres_method = fibres_method end |
Class Method Details
.nutrient_keys ⇒ Object
13 14 15 |
# File 'lib/nutriscore/uk/positive_score.rb', line 13 def self.nutrient_keys [:fvnp, :fibres, :proteins] end |
Instance Method Details
#fibres ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nutriscore/uk/positive_score.rb', line 27 def fibres score_value(@nutrients.fibres, 0..5) do |v| if @fibres_method == :aoac 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 elsif @fibres_method == :nsp if v > 3.5 then 5 elsif v > 2.8 then 4 elsif v > 2.1 then 3 elsif v > 1.4 then 2 elsif v > 0.7 then 1 else 0 end end end end |
#fvnp ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/nutriscore/uk/positive_score.rb', line 17 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 |
#proteins ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nutriscore/uk/positive_score.rb', line 49 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_proteins ⇒ Object
61 62 63 |
# File 'lib/nutriscore/uk/positive_score.rb', line 61 def score_without_proteins (self.class.nutrient_keys - [:proteins]).map(&method(:public_send)).compact.reduce(&:+) end |