Class: Rubybody::Food
- Inherits:
-
Object
- Object
- Rubybody::Food
- Defined in:
- lib/rubybody/nutrition.rb
Instance Attribute Summary collapse
-
#alcohol_grams ⇒ Object
Returns the value of attribute alcohol_grams.
-
#carb_grams ⇒ Object
Returns the value of attribute carb_grams.
-
#fat_grams ⇒ Object
Returns the value of attribute fat_grams.
-
#protein_grams ⇒ Object
Returns the value of attribute protein_grams.
Instance Method Summary collapse
- #calories ⇒ Object
-
#initialize(protein_grams, carb_grams, fat_grams, alcohol_grams = 0) ⇒ Food
constructor
All nutriments are expressed in grams.
Constructor Details
#initialize(protein_grams, carb_grams, fat_grams, alcohol_grams = 0) ⇒ Food
All nutriments are expressed in grams
13 14 15 16 17 18 |
# File 'lib/rubybody/nutrition.rb', line 13 def initialize(protein_grams, carb_grams, fat_grams, alcohol_grams=0) self.protein_grams = protein_grams self.carb_grams = carb_grams self.fat_grams = fat_grams self.alcohol_grams = alcohol_grams end |
Instance Attribute Details
#alcohol_grams ⇒ Object
Returns the value of attribute alcohol_grams.
10 11 12 |
# File 'lib/rubybody/nutrition.rb', line 10 def alcohol_grams @alcohol_grams end |
#carb_grams ⇒ Object
Returns the value of attribute carb_grams.
10 11 12 |
# File 'lib/rubybody/nutrition.rb', line 10 def carb_grams @carb_grams end |
#fat_grams ⇒ Object
Returns the value of attribute fat_grams.
10 11 12 |
# File 'lib/rubybody/nutrition.rb', line 10 def fat_grams @fat_grams end |
#protein_grams ⇒ Object
Returns the value of attribute protein_grams.
10 11 12 |
# File 'lib/rubybody/nutrition.rb', line 10 def protein_grams @protein_grams end |
Instance Method Details
#calories ⇒ Object
20 21 22 |
# File 'lib/rubybody/nutrition.rb', line 20 def calories return self.protein_grams * PROTEIN_CALORIES + self.carb_grams * CARB_CALORIES + self.fat_grams * FAT_CALORIES + self.alcohol_grams * ALCOHOL_CALORIES end |