Class: Alimento

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nutrientesEugenio.rb

Overview

Representación de un alimento según sus calorías aportadas y la cantidad de glucidos, proteinas y lipidos contenidos

Author:

  • Eugenio José Gonzalez Luis

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, grasas, g_sat, h_car, azucar, proteina, sal) ⇒ Alimento

Constructor de la clase alimento

Parameters:

  • nombre (String)

    nombre del alimento

  • grasas (Number)

    grasas contenidas en el alimento

  • g_sat (Number)

    grasas saturadas contenidas en el alimento

  • h_car (Number)

    hidratos de carbono contenidos en el alimento

  • azucar (Number)

    azucat contenidas en el alimento

  • proteina (Number)

    proteinas saturadas contenidas en el alimento

  • sal (Number)

    sal contenidos en el alimento

Since:

  • 1.0.0



28
29
30
31
32
33
34
35
36
# File 'lib/nutrientesEugenio.rb', line 28

def initialize(nombre, grasas, g_sat, h_car, azucar, proteina, sal)
    @nombre = nombre
    @grasas = grasas
    @g_sat = g_sat
    @h_car = h_car
    @azucar = azucar
    @proteina = proteina
    @sal = sal
end

Instance Attribute Details

#azucarObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def azucar
  @azucar
end

#g_satObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def g_sat
  @g_sat
end

#grasasObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def grasas
  @grasas
end

#h_carObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def h_car
  @h_car
end

#nombreObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def nombre
  @nombre
end

#NumberObject (readonly)

grasas grasas contenidas en el alimento

Returns:

  • (Object)

    the current value of Number



15
16
17
# File 'lib/nutrientesEugenio.rb', line 15

def Number
  @Number
end

#proteinaObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def proteina
  @proteina
end

#salObject (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/nutrientesEugenio.rb', line 16

def sal
  @sal
end

#StringObject (readonly)

nombre Nombre del alimento

Returns:

  • (Object)

    the current value of String



15
16
17
# File 'lib/nutrientesEugenio.rb', line 15

def String
  @String
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Metodo para comparar dos alimentos

Parameters:

  • otro (Alimento)

    alimento a comparar

Returns:

  • (-1, 0, 1)

    -1 si es menor, 0 si son iguales, 1 si es mayor

Since:

  • 1.0.0



59
60
61
# File 'lib/nutrientesEugenio.rb', line 59

def <=>(other)
    kcal <=> other.kcal
end

#cantidad_salString

Metodo que clasifica alimentos segun su cantidad de sal

Returns:

  • (String)

    devuelve un string con la clasificación

Since:

  • 1.0.0



66
67
68
69
70
71
72
# File 'lib/nutrientesEugenio.rb', line 66

def cantidad_sal
   if(sal < 0.6)
       return "poca"
   else
       return "mucha"
   end
end

#kcalNumber

Calcula las calorias

Returns:

Since:

  • 1.0.0



51
52
53
# File 'lib/nutrientesEugenio.rb', line 51

def kcal
    @proteina * 4 + @h_car * 4 + @grasas * 9
end

#to_sString

Convierte el objeto a una cadena de caracteres

Returns:

  • (String)

    devuelve el alimento como un string

Since:

  • 1.0.0



40
41
42
43
44
45
46
# File 'lib/nutrientesEugenio.rb', line 40

def to_s
    "#{@nombre}:
  #{@grasas} g grasa de los cuales saturados: #{@g_sat}
  #{@h_car} g hidratos de carbono de los cuales azucares: #{@azucar}
  #{@proteina} g proteinas
  #{@sal} g sal"
end