nutriscore 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32fc807c0ac252fb44029dd894b01c6e1a73cdb018818683265bcfbaf28e6414
4
- data.tar.gz: e52bbc975c607d50c68f308ccb0c374841a8cfc209b2e176b88c2b1ae22cf97c
3
+ metadata.gz: 5546badbbce48d13c565aa9adb7e0acccd1625916f11dcc77f34fb7fcb0571a6
4
+ data.tar.gz: b884ceed940198537890c1d81be684baa0c30ff885776f9b661c22da5595c4f7
5
5
  SHA512:
6
- metadata.gz: 60a6712c438ea99a6ea46560327fa25f8519bc80aefb8e65a3eaf272568f53a4ce08219731656b02f8eada7ed28bc48385173107ed767221d9002334b3d2cda3
7
- data.tar.gz: 36571b3a8c1930043e961ef776f5bbdfa958da5f2759cd029ab555ac5354dbbbc9e2251aa11242a9006cc1b27efa401759764bdbd0f8e629529700c346f2c392
6
+ metadata.gz: ec3de5c8ceaa94d7d445c8a25c95eaeb4f13133a4bcfd709513c86ce8b0b7a80753fe73fe96a42892f851079ac0090cecf49f536c6fd6db1d0c094bc0c1a6ead
7
+ data.tar.gz: f6854b82b1fe9ba3ac30552466d16b79c85f6684beb48829f057300d758f883e36e923a53a34df03863e81965b58d2e617bc4f5dd3862aa85e6013902ee392eb
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Nutriscore
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/nutriscore.svg)](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 is also a
28
- [European citizen's initiative](http://ec.europa.eu/citizens-initiative/public/initiatives/ongoing/details/2019/000008)
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, # kJ/100g
48
- fat_saturated: 1.8, # g/100g
49
- sugar: 13.4, # g/100g
50
- sodium: 0.1 / 1000, # g/100g
51
- fruits_vegetables_nuts: 8, # g/100g (= weight-%)
52
- fibres: 0.6, # g/100g
53
- proteins: 6.5, # g/100g
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
- # fruits_vegetables_nuts=0 fibres=0 proteins=4>
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, :fruits_vegetables]
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 fruits_vegetables
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.fruits_vegetables, 0..10) do |v|
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 0
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
- [:fruits_vegetables_nuts, :fibres, :proteins]
8
+ [:fvnp, :fibres, :proteins]
9
9
  end
10
10
 
11
- def fruits_vegetables_nuts
12
- score_value(@nutrients.fruits_vegetables_nuts, 0..5) do |v|
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.fruits_vegetables_nuts.max >= 5
9
+ if @negative.score.min < 11 || @positive.fvnp.max >= 5
10
10
  @negative.score - @positive.score
11
- elsif @negative.score.max >= 11 && @positive.fruits_vegetables_nuts.min < 5
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
- [:fruits_vegetables_nuts, :fibres, :proteins]
14
+ [:fvnp, :fibres, :proteins]
15
15
  end
16
16
 
17
- def fruits_vegetables_nuts
18
- score_value(@nutrients.fruits_vegetables_nuts, 0..5) do |v|
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 nuts.'
11
- if @negative.score.min < 11 || @positive.fruits_vegetables_nuts.max >= 5
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.fruits_vegetables_nuts.min < 5
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(
@@ -1,4 +1,4 @@
1
1
  module Nutriscore
2
- VERSION = '0.2.0'
3
- VERSION_DATE = '2021-06-07'
2
+ VERSION = '0.3.0'
3
+ VERSION_DATE = '2022-05-05'
4
4
  end
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.2.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: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec