Class: Alimento
- Inherits:
-
Object
- Object
- Alimento
- Includes:
- Comparable
- Defined in:
- lib/nutrientes/alimento.rb
Overview
Esta clase representa a un alimento
Direct Known Subclasses
AlimentosGrasos, AlimentosRenC, CarnesyDerivados, Frutas, HLH, Pescadosymariscos, VeyHo
Instance Attribute Summary collapse
-
#glucidos ⇒ Object
readonly
Permite la lectura de estas variables.
-
#indexglucosa ⇒ Object
readonly
Permite la lectura de estas variables.
-
#lipidos ⇒ Object
readonly
Permite la lectura de estas variables.
-
#nombre ⇒ Object
readonly
Permite la lectura de estas variables.
-
#proteinas ⇒ Object
readonly
Permite la lectura de estas variables.
Instance Method Summary collapse
-
#<=>(anOther) ⇒ bool
Operador <=> para el modulo Comparable.
-
#calculate_index(data, glucosa) ⇒ Object
Calcula el indice glucemico de un alimento.
-
#initialize(nombre, p, g, l) ⇒ Alimento
constructor
A new instance of Alimento.
-
#to_s ⇒ Object
Converts the object into a string.
-
#v_energetico ⇒ Integer
Este metodo calcula el valor energetico de un alimento.
Constructor Details
#initialize(nombre, p, g, l) ⇒ Alimento
Returns a new instance of Alimento
10 11 12 13 14 15 16 |
# File 'lib/nutrientes/alimento.rb', line 10 def initialize(nombre, p, g, l) @nombre = nombre @proteinas = p @glucidos = g @lipidos = l @indexglucosa = nil end |
Instance Attribute Details
#glucidos ⇒ Object (readonly)
Permite la lectura de estas variables
8 9 10 |
# File 'lib/nutrientes/alimento.rb', line 8 def glucidos @glucidos end |
#indexglucosa ⇒ Object (readonly)
Permite la lectura de estas variables
8 9 10 |
# File 'lib/nutrientes/alimento.rb', line 8 def indexglucosa @indexglucosa end |
#lipidos ⇒ Object (readonly)
Permite la lectura de estas variables
8 9 10 |
# File 'lib/nutrientes/alimento.rb', line 8 def lipidos @lipidos end |
#nombre ⇒ Object (readonly)
Permite la lectura de estas variables
8 9 10 |
# File 'lib/nutrientes/alimento.rb', line 8 def nombre @nombre end |
#proteinas ⇒ Object (readonly)
Permite la lectura de estas variables
8 9 10 |
# File 'lib/nutrientes/alimento.rb', line 8 def proteinas @proteinas end |
Instance Method Details
#<=>(anOther) ⇒ bool
Operador <=> para el modulo Comparable
66 67 68 |
# File 'lib/nutrientes/alimento.rb', line 66 def <=>(anOther) return self.v_energetico <=> anOther.v_energetico end |
#calculate_index(data, glucosa) ⇒ Object
Calcula el indice glucemico de un alimento
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nutrientes/alimento.rb', line 22 def calculate_index(data, glucosa) aibc = [] aibc_gluc = [] data.each do |x| t = 0 x.each_index do |a| if (a != 0) t += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5 end end aibc << t end glucosa.each do |x| t = 0 x.each_index do |a| if (a != 0) t += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5 end end aibc_gluc << t end igind = [] aibc.each_index { |x| igind << ((aibc[x] / aibc_gluc[x]) * 100)} suma = 0 igind.each{ |x| suma += x} @indexglucosa = (suma / igind.length) end |
#to_s ⇒ Object
Converts the object into a string
52 53 54 |
# File 'lib/nutrientes/alimento.rb', line 52 def to_s() return "Nombre: #{@nombre}, Proteinas: #{@proteinas}gr, GlĂșcidos: #{@glucidos}gr, Lipidos: #{@lipidos}gr" end |
#v_energetico ⇒ Integer
Este metodo calcula el valor energetico de un alimento
58 59 60 |
# File 'lib/nutrientes/alimento.rb', line 58 def v_energetico() return (@proteinas * 4 + @glucidos * 4 + @lipidos * 9) end |