Class: Nutriscore::UK::SpecificScore

Inherits:
GeneralScore show all
Defined in:
lib/nutriscore/uk/specific_score.rb

Overview

this is for general products

Direct Known Subclasses

DrinksScore

Instance Attribute Summary

Attributes inherited from GeneralScore

#negative, #positive

Instance Method Summary collapse

Methods inherited from GeneralScore

#initialize, #inspect, nutrient_keys

Methods included from GeneralLessHealthy

#less_healthy?

Constructor Details

This class inherits a constructor from Nutriscore::UK::GeneralScore

Instance Method Details

#scoreObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nutriscore/uk/specific_score.rb', line 8

def score
  # 'If a food or drink scores 11 or more ‘A’ points then it cannot score points for protein
  #  unless it also scores 5 points for fruit, vegetables, nuts and pulses.'
  if @negative.score.min < 11 || @positive.fvnp.max >= 5
    @negative.score - @positive.score
  elsif @negative.score.max >= 11 && @positive.fvnp.min < 5
    @negative.score - @positive.score_without_proteins
  else
    Range.new(
      @negative.score.min - @positive.score.max,
      @negative.score.max - @positive.score_without_proteins.min
    )
  end
end