Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ Menu

Returns a new instance of Menu.



7
8
9
10
11
12
13
14
15
16
# File 'lib/etiqueta_nutricional/menu.rb', line 7

def initialize(nombre, &block)
  @nombre = nombre
  @desayuno = []
  @almuerzo = []
  @cena = []
  
  if block_given?  
    instance_eval(&block) 
  end
end

Instance Attribute Details

#ingesta(ing = {}) ⇒ Object

Returns the value of attribute ingesta.



5
6
7
# File 'lib/etiqueta_nutricional/menu.rb', line 5

def ingesta
  @ingesta
end

#nombreObject

Returns the value of attribute nombre.



5
6
7
# File 'lib/etiqueta_nutricional/menu.rb', line 5

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



5
6
7
# File 'lib/etiqueta_nutricional/menu.rb', line 5

def platos
  @platos
end

Instance Method Details

#almuerzo(alm = {}) ⇒ Object



26
27
28
# File 'lib/etiqueta_nutricional/menu.rb', line 26

def almuerzo(alm = {})
  @almuerzo << Etiqueta.new(alm[:descripcion], alm[:grasas], alm[:fibra], alm[:carbohidratos], 0, alm[:proteinas], alm[:sal], [alm[:porcion], alm[:gramos]])
end

#cena(cen = {}) ⇒ Object



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

def cena(cen = {})
  @cena << Etiqueta.new(cen[:descripcion], cen[:grasas], cen[:fibra], cen[:carbohidratos], 0, cen[:proteinas], cen[:sal], [cen[:porcion], cen[:gramos]])
end

#desayuno(des = {}) ⇒ Object



22
23
24
# File 'lib/etiqueta_nutricional/menu.rb', line 22

def desayuno(des = {})
  @desayuno << Etiqueta.new(des[:descripcion], des[:grasas], des[:fibra], des[:carbohidratos], 0, des[:proteinas], des[:sal], [des[:porcion], des[:gramos]])
end

#kcalObject



39
40
41
# File 'lib/etiqueta_nutricional/menu.rb', line 39

def kcal
  300#(@desayuno.reduce(:+) + @almuerzo.reduce(:+) + @cena.reduce(:+)).round(2)
end

#titulo(str) ⇒ Object



18
19
20
# File 'lib/etiqueta_nutricional/menu.rb', line 18

def titulo(str)
  @title = str
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/etiqueta_nutricional/menu.rb', line 43

def to_s
  output = Tabla.new
  output << @nombre 
  output << '' << 'Grasas' << 'Carbohidratos' << 'Proteinas' << 'Fibra' << 'Sal' << 'Valor energético'
  output << 'Desayuno'
  @desayuno.each do |des|
    output << des.obtener_nombre << des.obtener_grasas.to_s << des.obtener_hidratos_carbono.to_s << des.obtener_proteinas.to_s << des.obtener_grasas_saturadas << des.obtener_sal.to_s << des.obtener_valor_energetico_kcal.round(2).to_s
  end
  output << ''
  output << 'Almuerzo'
  @almuerzo.each do |alm|
    output << alm.obtener_nombre << alm.obtener_grasas.to_s << alm.obtener_hidratos_carbono.to_s << alm.obtener_proteinas.to_s << alm.obtener_grasas_saturadas << alm.obtener_sal.to_s << alm.obtener_valor_energetico_kcal.round(2).to_s
  end
  output << ''
  output << 'Cena'
  @cena.each do |cen|
    output << cen.obtener_nombre << cen.obtener_grasas.to_s << cen.obtener_hidratos_carbono.to_s << cen.obtener_proteinas.to_s << cen.obtener_grasas_saturadas << cen.obtener_sal.to_s << cen.obtener_valor_energetico_kcal.round(2).to_s
  end
  output << ''
  output << 'Valor energético total' << self.kcal
  return output.to_s
end