Class: DishImpact
Instance Attribute Summary collapse
-
#e_fp ⇒ Object
readonly
Returns the value of attribute e_fp.
-
#foodList ⇒ Object
readonly
Returns the value of attribute foodList.
-
#grams ⇒ Object
readonly
Returns the value of attribute grams.
-
#n_fp ⇒ Object
readonly
Returns the value of attribute n_fp.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #dailygei ⇒ Object
- #geiMean ⇒ Object
-
#initialize(name, foods, grams) ⇒ DishImpact
constructor
A new instance of DishImpact.
- #nutritional_footprints ⇒ Object
- #terrainTotal ⇒ Object
- #to_s ⇒ Object
Methods inherited from Dish
#energyMean, #pch, #plip, #pprot, #tcv
Constructor Details
#initialize(name, foods, grams) ⇒ DishImpact
Returns a new instance of DishImpact.
15 16 17 18 |
# File 'lib/DishImpact.rb', line 15 def initialize(name, foods ,grams) super(name, foods ,grams) nutritional_footprints end |
Instance Attribute Details
#e_fp ⇒ Object (readonly)
Returns the value of attribute e_fp.
13 14 15 |
# File 'lib/DishImpact.rb', line 13 def e_fp @e_fp end |
#foodList ⇒ Object (readonly)
Returns the value of attribute foodList.
13 14 15 |
# File 'lib/DishImpact.rb', line 13 def foodList @foodList end |
#grams ⇒ Object (readonly)
Returns the value of attribute grams.
13 14 15 |
# File 'lib/DishImpact.rb', line 13 def grams @grams end |
#n_fp ⇒ Object (readonly)
Returns the value of attribute n_fp.
13 14 15 |
# File 'lib/DishImpact.rb', line 13 def n_fp @n_fp end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/DishImpact.rb', line 13 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
80 81 82 83 84 |
# File 'lib/DishImpact.rb', line 80 def <=>(other) return nil unless other.instance_of? DishImpact terrainTotal + dailygei <=> other.terrainTotal + other.dailygei end |
#dailygei ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/DishImpact.rb', line 19 def dailygei current = @foodList.head total = 0 count = 0 while current total += (current.value.gei * @grams[count]) count += 1 current = current.next end total end |
#geiMean ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/DishImpact.rb', line 42 def geiMean current = @foodList.head total = 0 count = 0 while current total += (current.value.gei * @grams[count]) count += 1 current = current.next end total/foodList.length end |
#nutritional_footprints ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/DishImpact.rb', line 55 def nutritional_footprints @n_fp = 0 if energyMean < 670 then @n_fp = 1 elsif energyMean > 830 then @n_fp = 3 else @n_fp = 2 end @e_fp = 0 if dailygei < 800 then @e_fp = 1 elsif dailygei > 1200 then @e_fp = 3 else @e_fp = 2 end end |
#terrainTotal ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/DishImpact.rb', line 30 def terrainTotal current = @foodList.head total = 0 count = 0 while current total += (current.value.terrain * @grams[count]) count += 1 current = current.next end total end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/DishImpact.rb', line 76 def to_s "(: #{@name} : gei [#{dailygei}] | terrain [#{terrainTotal}] :)" end |