class Food
Class for Food
that inherit FoodAbstract
Attributes
group_name[R]
@attr_reader group_name
[String] name the name of the food group
Public Class Methods
new(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name = "", gluc_sample_pair_array = [])
click to toggle source
Constructor of Food
with the group name @param name [String] the name for the food. @param protein_energy_pair [pair] pair of protein number and energy. @param glucid_energy_pair [pair] pair of glucid number and energy @param lipid_energy_pair [pair] pair of lipid number and energy @param group_name
[String] the name for the food group.
Calls superclass method
FoodAbstract::new
# 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
Public Instance Methods
<=>(food)
click to toggle source
Essential comparating for using Comparable Module @return [String] Return which food is higher depending on the enrgetic content
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/food/food_class.rb, line 116 def get_ig_of_person(person_number) return @ig_array[person_number-1] end
to_s()
click to toggle source
Return string with the output for the food calling the father @return [String] output of food
Calls superclass method
FoodAbstract#to_s
# File lib/food/food_class.rb, line 126 def to_s return ("Grupo: #{@group_name} | " + super) if (@group_name != "") super end
Private Instance Methods
calculate_aibc(sample_array)
click to toggle source
# File lib/food/food_class.rb, line 102 def calculate_aibc(sample_array) (1...sample_array.size).map{|i| ((sample_array[i] + sample_array[i-1] - 2*sample_array[0]) / 2) * 5}.reduce(:+) end
calculate_ig_for_person(person_number)
click to toggle source
# File lib/food/food_class.rb, line 106 def calculate_ig_for_person(person_number) return ((@aibc_food_array[person_number-1] / @aibc_glucose_array[person_number-1]) * 100) end