nutriscore 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -12
- data/lib/nutriscore/fr/drinks_score.rb +3 -3
- data/lib/nutriscore/fr/negative_score.rb +2 -1
- data/lib/nutriscore/fr/positive_score.rb +3 -3
- data/lib/nutriscore/fr/specific_score.rb +2 -2
- data/lib/nutriscore/uk/positive_score.rb +3 -3
- data/lib/nutriscore/uk/specific_score.rb +3 -3
- data/lib/nutriscore/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5546badbbce48d13c565aa9adb7e0acccd1625916f11dcc77f34fb7fcb0571a6
|
4
|
+
data.tar.gz: b884ceed940198537890c1d81be684baa0c30ff885776f9b661c22da5595c4f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec3de5c8ceaa94d7d445c8a25c95eaeb4f13133a4bcfd709513c86ce8b0b7a80753fe73fe96a42892f851079ac0090cecf49f536c6fd6db1d0c094bc0c1a6ead
|
7
|
+
data.tar.gz: f6854b82b1fe9ba3ac30552466d16b79c85f6684beb48829f057300d758f883e36e923a53a34df03863e81965b58d2e617bc4f5dd3862aa85e6013902ee392eb
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Nutriscore
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/nutriscore)
|
4
|
+
|
3
5
|
Consumer food products in some countries have a nutritional score, indicating
|
4
6
|
how healthy the product is to eat. Each country has its own approach, but in
|
5
7
|
the European Union the _Nutri-Score_ in several countries.
|
@@ -24,9 +26,9 @@ was adopted in 2017 for use as a voluntary label on the packaging.
|
|
24
26
|
In 2018, Belgium and Spain adopted the same scheme.
|
25
27
|
|
26
28
|
Other countries are evaluating adopting the Nutri-Score as well, including
|
27
|
-
The Netherlands. There
|
28
|
-
[European citizen's initiative](http://ec.europa.eu/citizens-initiative/public/initiatives/ongoing/details/2019/
|
29
|
-
to adopt it Europe-wide.
|
29
|
+
The Netherlands. There was also a
|
30
|
+
[European citizen's initiative](http://ec.europa.eu/citizens-initiative/public/initiatives/ongoing/details/2019/000008_en)
|
31
|
+
to adopt it Europe-wide, but this has been withdrawn.
|
30
32
|
|
31
33
|
## Installation
|
32
34
|
|
@@ -37,27 +39,29 @@ gem install nutriscore
|
|
37
39
|
## Usage
|
38
40
|
|
39
41
|
The input for all nutritional scores are a product category and nutritional values.
|
40
|
-
Which nutrients are required depends on the product category.
|
42
|
+
Which nutrients are required depends on the product category. Note that `fvnp` stands
|
43
|
+
for the amount of fruits, vegetables, nuts and pulses (and, since Oct 2019, also
|
44
|
+
rapeseed, walnuts and olive oils).
|
41
45
|
|
42
46
|
```ruby
|
43
47
|
require 'nutriscore'
|
44
48
|
|
45
49
|
# Fruit fromage frais
|
46
50
|
product_a = {
|
47
|
-
energy: 459,
|
48
|
-
fat_saturated: 1.8,
|
49
|
-
sugar: 13.4,
|
50
|
-
sodium: 0.1
|
51
|
-
|
52
|
-
fibres: 0.6,
|
53
|
-
proteins: 6.5,
|
51
|
+
energy: 459, # kJ/100g
|
52
|
+
fat_saturated: 1.8, # g/100g
|
53
|
+
sugar: 13.4, # g/100g
|
54
|
+
sodium: 0.1, # g/100g
|
55
|
+
fvnp: 8, # g/100g (= weight-%)
|
56
|
+
fibres: 0.6, # g/100g
|
57
|
+
proteins: 6.5, # g/100g
|
54
58
|
}
|
55
59
|
|
56
60
|
# Compute the french Nutri-Score for a generic product.
|
57
61
|
score = Nutriscore::FR::SpecificScore.new(product_a)
|
58
62
|
#<Nutriscore::FR::SpecificScore score=0
|
59
63
|
# positive_score=#<Nutriscore::FR::PositiveScore score=4
|
60
|
-
#
|
64
|
+
# fvnp=0 fibres=0 proteins=4>
|
61
65
|
# negative_score=#<Nutriscore::FR::NegativeScore score=4
|
62
66
|
# energy=1 fat_saturated=1 sugar=2 sodium=0>>
|
63
67
|
score.score.single
|
@@ -8,7 +8,7 @@ module Nutriscore
|
|
8
8
|
include DrinksScoreClass
|
9
9
|
|
10
10
|
def self.nutrient_keys
|
11
|
-
[:energy, :sugar, :
|
11
|
+
[:energy, :sugar, :fvnp]
|
12
12
|
end
|
13
13
|
|
14
14
|
def energy
|
@@ -45,10 +45,10 @@ module Nutriscore
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def fvnp
|
49
49
|
# the text mentions % but here we use g/100ml
|
50
50
|
# we'd need to either ask for %, ask for g/100g, or require a density ...
|
51
|
-
score_value(@nutrients.
|
51
|
+
score_value(@nutrients.fvnp, 0..10) do |v|
|
52
52
|
if v > 80 then 10
|
53
53
|
elsif v > 60 then 4
|
54
54
|
elsif v > 40 then 2
|
@@ -37,7 +37,7 @@ module Nutriscore
|
|
37
37
|
elsif v > 3 then 3
|
38
38
|
elsif v > 2 then 2
|
39
39
|
elsif v > 1 then 1
|
40
|
-
else
|
40
|
+
else 0
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -61,6 +61,7 @@ module Nutriscore
|
|
61
61
|
|
62
62
|
def sodium
|
63
63
|
score_value(@nutrients.sodium, 0..10) do |v|
|
64
|
+
v *= 1000 if v # comparison is in mg/100g
|
64
65
|
if v > 900 then 10
|
65
66
|
elsif v > 810 then 9
|
66
67
|
elsif v > 720 then 8
|
@@ -5,11 +5,11 @@ module Nutriscore
|
|
5
5
|
class PositiveScore < Nutriscore::Common::Score
|
6
6
|
|
7
7
|
def self.nutrient_keys
|
8
|
-
[:
|
8
|
+
[:fvnp, :fibres, :proteins]
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
score_value(@nutrients.
|
11
|
+
def fvnp
|
12
|
+
score_value(@nutrients.fvnp, 0..5) do |v|
|
13
13
|
if v > 80 then 5
|
14
14
|
elsif v > 60 then 2
|
15
15
|
elsif v > 40 then 1
|
@@ -6,9 +6,9 @@ module Nutriscore
|
|
6
6
|
# this is for general products
|
7
7
|
class SpecificScore < GeneralScore
|
8
8
|
def score
|
9
|
-
if @negative.score.min < 11 || @positive.
|
9
|
+
if @negative.score.min < 11 || @positive.fvnp.max >= 5
|
10
10
|
@negative.score - @positive.score
|
11
|
-
elsif @negative.score.max >= 11 && @positive.
|
11
|
+
elsif @negative.score.max >= 11 && @positive.fvnp.min < 5
|
12
12
|
@negative.score - @positive.score_without_proteins
|
13
13
|
else
|
14
14
|
Range.new(
|
@@ -11,11 +11,11 @@ module Nutriscore
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.nutrient_keys
|
14
|
-
[:
|
14
|
+
[:fvnp, :fibres, :proteins]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
score_value(@nutrients.
|
17
|
+
def fvnp
|
18
|
+
score_value(@nutrients.fvnp, 0..5) do |v|
|
19
19
|
if v > 80 then 5
|
20
20
|
elsif v > 60 then 2
|
21
21
|
elsif v > 40 then 1
|
@@ -7,10 +7,10 @@ module Nutriscore
|
|
7
7
|
class SpecificScore < GeneralScore
|
8
8
|
def score
|
9
9
|
# 'If a food or drink scores 11 or more ‘A’ points then it cannot score points for protein
|
10
|
-
# unless it also scores 5 points for fruit, vegetables and
|
11
|
-
if @negative.score.min < 11 || @positive.
|
10
|
+
# unless it also scores 5 points for fruit, vegetables, nuts and pulses.'
|
11
|
+
if @negative.score.min < 11 || @positive.fvnp.max >= 5
|
12
12
|
@negative.score - @positive.score
|
13
|
-
elsif @negative.score.max >= 11 && @positive.
|
13
|
+
elsif @negative.score.max >= 11 && @positive.fvnp.min < 5
|
14
14
|
@negative.score - @positive.score_without_proteins
|
15
15
|
else
|
16
16
|
Range.new(
|
data/lib/nutriscore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nutriscore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wvengen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|