Class: Rubybody::Food

Inherits:
Object
  • Object
show all
Defined in:
lib/rubybody/nutrition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_gramsObject

Returns the value of attribute alcohol_grams.



10
11
12
# File 'lib/rubybody/nutrition.rb', line 10

def alcohol_grams
  @alcohol_grams
end

#carb_gramsObject

Returns the value of attribute carb_grams.



10
11
12
# File 'lib/rubybody/nutrition.rb', line 10

def carb_grams
  @carb_grams
end

#fat_gramsObject

Returns the value of attribute fat_grams.



10
11
12
# File 'lib/rubybody/nutrition.rb', line 10

def fat_grams
  @fat_grams
end

#protein_gramsObject

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

#caloriesObject



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