Class: Alimento

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, grasas, grsat, carbs, azucar, protein, sal) ⇒ Alimento

Returns a new instance of Alimento.



9
10
11
12
13
14
15
16
17
18
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 9

def initialize(nombre, grasas, grsat, carbs, azucar, protein, sal)
  @nombre = nombre
  @grasas = grasas
  @grsat = grsat
  @carbs = carbs
  @azucar = azucar
  @protein = protein
  @sal = sal
  
end

Instance Attribute Details

#azucarObject (readonly)

Returns the value of attribute azucar.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def azucar
  @azucar
end

#carbsObject (readonly)

Returns the value of attribute carbs.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def carbs
  @carbs
end

#grasasObject (readonly)

Returns the value of attribute grasas.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def grasas
  @grasas
end

#grsatObject (readonly)

Returns the value of attribute grsat.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def grsat
  @grsat
end

#nombreObject (readonly)

Returns the value of attribute nombre.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def nombre
  @nombre
end

#proteinObject (readonly)

Returns the value of attribute protein.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def protein
  @protein
end

#salObject (readonly)

Returns the value of attribute sal.



7
8
9
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 7

def sal
  @sal
end

Instance Method Details

#<=>(other) ⇒ Object



30
31
32
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 30

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

#to_sObject



25
26
27
28
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 25

def to_s
  "Nombre: #{@nombre}, Grasas: #{@grasas}, Saturadas: #{@grsat}, Carbohidratos: #{@carbs}, Azucar: #{@azucar}, Proteinas: #{@protein}, Sal: #{@sal} Kcal: #{val_ener}
  "
end

#val_enerObject



20
21
22
# File 'lib/NutrientesEdu/NutrientesEdu.rb', line 20

def val_ener
  (grasas*9+carbs*4+protein*4)
end