Class: Food

Inherits:
FoodAbstract show all
Includes:
Comparable
Defined in:
lib/food/food_class.rb

Overview

Class for Food that inherit FoodAbstract

Instance Attribute Summary collapse

Attributes inherited from FoodAbstract

#energetic_content, #glucemic_, #glucid_quantity, #lipid_quantity, #name, #protein_quantity

Instance Method Summary collapse

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

Parameters:

  • name (String)

    the name for the food.

  • protein_energy_pair (pair)

    pair of protein number and energy.

  • glucid_energy_pair (pair)

    pair of glucid number and energy

  • lipid_energy_pair (pair)

    pair of lipid number and energy

  • group_name (String) (defaults to: "")

    the name for the food group.



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_nameObject (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

Returns:

  • (String)

    Return which food is higher depending on the enrgetic content



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_igObject



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_sString

Return string with the output for the food calling the father

Returns:

  • (String)

    output of food



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