Class: Food
- Inherits:
-
FoodAbstract
- Object
- FoodAbstract
- Food
- Includes:
- Comparable
- Defined in:
- lib/food/food_class.rb
Overview
Class for Food that inherit FoodAbstract
Instance Attribute Summary collapse
- #group_name ⇒ Object readonly
Attributes inherited from FoodAbstract
#energetic_content, #glucemic_, #glucid_quantity, #lipid_quantity, #name, #protein_quantity
Instance Method Summary collapse
-
#<=>(food) ⇒ String
Essential comparating for using Comparable Module.
- #get_aibc_of_person(person_number) ⇒ Object
- #get_ig ⇒ Object
- #get_ig_of_person(person_number) ⇒ Object
-
#initialize(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name = "", gluc_sample_pair_array = []) ⇒ Food
constructor
Constructor of Food with the group name.
-
#to_s ⇒ String
Return string with the output for the food calling the father.
Methods inherited from FoodAbstract
#*, #calculate_energetic_content
Constructor Details
#initialize(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name = "", gluc_sample_pair_array = []) ⇒ Food
Constructor of Food with the group name
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/food/food_class.rb', line 85 def initialize(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name = "", gluc_sample_pair_array = []) @group_name = group_name super(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair) @aibc_food_array = [] # The AIBC of this food for each person @aibc_glucose_array = [] # The AIBC of glucose for each person @ig_array = [] # The IG of this food for each person gluc_sample_pair_array.each { |person_array| @aibc_food_array.push(calculate_aibc(person_array[0])) # First is the samples of this food for a person @aibc_glucose_array.push(calculate_aibc(person_array[1])) # First is the samples of glucose for a person @ig_array.push(calculate_ig_for_person(@aibc_food_array.size)) } end |
Instance Attribute Details
#group_name ⇒ Object (readonly)
77 78 79 |
# File 'lib/food/food_class.rb', line 77 def group_name @group_name end |
Instance Method Details
#<=>(food) ⇒ String
Essential comparating for using Comparable Module
133 134 135 136 137 |
# File 'lib/food/food_class.rb', line 133 def <=> (food) raise unless food.is_a?Food # return self.energetic_content <=> food.energetic_content return self.name <=> food.name end |
#get_aibc_of_person(person_number) ⇒ Object
112 113 114 |
# File 'lib/food/food_class.rb', line 112 def get_aibc_of_person(person_number) return @aibc_food_array[person_number-1] end |
#get_ig ⇒ Object
120 121 122 |
# File 'lib/food/food_class.rb', line 120 def get_ig return (@ig_array.reduce(:+) / @ig_array.size) end |
#get_ig_of_person(person_number) ⇒ Object
116 117 118 |
# File 'lib/food/food_class.rb', line 116 def get_ig_of_person(person_number) return @ig_array[person_number-1] end |
#to_s ⇒ String
Return string with the output for the food calling the father
126 127 128 129 |
# File 'lib/food/food_class.rb', line 126 def to_s return ("Grupo: #{@group_name} | " + super) if (@group_name != "") super end |