Class: Nutrition_Info

Inherits:
Object
  • Object
show all
Defined in:
lib/Prct07/Nutrition_Info.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hidrates, proteins, fats, calories) ⇒ Nutrition_Info

Returns a new instance of Nutrition_Info.



5
6
7
8
9
10
# File 'lib/Prct07/Nutrition_Info.rb', line 5

def initialize(hidrates, proteins, fats, calories)
  @Hidrates = check_great_zero hidrates
  @Proteins = check_great_zero proteins
  @Fats = check_great_zero fats
  @Calories = check_great_zero calories
end

Instance Attribute Details

#CaloriesObject (readonly)

Returns the value of attribute Calories.



3
4
5
# File 'lib/Prct07/Nutrition_Info.rb', line 3

def Calories
  @Calories
end

#FatsObject (readonly)

Returns the value of attribute Fats.



3
4
5
# File 'lib/Prct07/Nutrition_Info.rb', line 3

def Fats
  @Fats
end

#HidratesObject (readonly)

Returns the value of attribute Hidrates.



3
4
5
# File 'lib/Prct07/Nutrition_Info.rb', line 3

def Hidrates
  @Hidrates
end

#ProteinsObject (readonly)

Returns the value of attribute Proteins.



3
4
5
# File 'lib/Prct07/Nutrition_Info.rb', line 3

def Proteins
  @Proteins
end

Instance Method Details

#check_great_zero(param) ⇒ Object

checks if the argument is valid



13
14
15
16
17
18
19
# File 'lib/Prct07/Nutrition_Info.rb', line 13

def check_great_zero(param)
  if (param < 0)
    0
  else
    param
  end
end

#to_sObject

necessary for puts method



22
23
24
# File 'lib/Prct07/Nutrition_Info.rb', line 22

def to_s
  "hidrates: " + @Hidrates.to_s + ", proteins: " + @Proteins.to_s + ", fats: " + @Fats.to_s + ", kilocalories: " + @Calories.to_s
end