Class: Nutriscore::UK::GeneralScore

Inherits:
Object
  • Object
show all
Includes:
GeneralLessHealthy
Defined in:
lib/nutriscore/uk/general_score.rb

Direct Known Subclasses

SpecificScore

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GeneralLessHealthy

#less_healthy?

Constructor Details

#initialize(nutrients, fibres_method: :aoac) ⇒ GeneralScore

Returns a new instance of GeneralScore.



17
18
19
20
21
# File 'lib/nutriscore/uk/general_score.rb', line 17

def initialize(nutrients, fibres_method: :aoac)
  @nutrients = Nutriscore::Common::Nutrients.wrap(nutrients)
  @positive = PositiveScore.new(@nutrients, fibres_method: fibres_method)
  @negative = NegativeScore.new(@nutrients)
end

Instance Attribute Details

#negativeObject (readonly)

Returns the value of attribute negative.



11
12
13
# File 'lib/nutriscore/uk/general_score.rb', line 11

def negative
  @negative
end

#positiveObject (readonly)

Returns the value of attribute positive.



11
12
13
# File 'lib/nutriscore/uk/general_score.rb', line 11

def positive
  @positive
end

Class Method Details

.nutrient_keysObject



13
14
15
# File 'lib/nutriscore/uk/general_score.rb', line 13

def self.nutrient_keys
  PositiveScore.nutrient_keys | NegativeScore.nutrient_keys
end

Instance Method Details

#inspectObject



27
28
29
30
# File 'lib/nutriscore/uk/general_score.rb', line 27

def inspect
  "#<#{self.class} score=#{score} " +
    "positive_score=#{@positive.inspect} negative_score=#{@negative.inspect}>"
end

#scoreObject



23
24
25
# File 'lib/nutriscore/uk/general_score.rb', line 23

def score
  @negative.score - @positive.score
end