Class: Nutriscore::Common::Score

Inherits:
Object
  • Object
show all
Defined in:
lib/nutriscore/common/score.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nutrients) ⇒ Score

Returns a new instance of Score.



17
18
19
# File 'lib/nutriscore/common/score.rb', line 17

def initialize(nutrients)
  @nutrients = Nutrients.wrap(nutrients)
end

Instance Attribute Details

#nutrientsObject (readonly)

Returns the value of attribute nutrients.



7
8
9
# File 'lib/nutriscore/common/score.rb', line 7

def nutrients
  @nutrients
end

Class Method Details

.nutrient_keysObject



9
10
11
# File 'lib/nutriscore/common/score.rb', line 9

def self.nutrient_keys
  []
end

Instance Method Details

#inspectObject



21
22
23
# File 'lib/nutriscore/common/score.rb', line 21

def inspect
  "#<#{self.class} score=#{score} #{inspect_nutrients}>"
end

#scoreObject



13
14
15
# File 'lib/nutriscore/common/score.rb', line 13

def score
  self.class.nutrient_keys.map(&method(:public_send)).reduce(&:+)
end