Class: MenuFacil

Inherits:
Object
  • Object
show all
Defined in:
lib/alu0100406580_nutricion/menuDSL.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ MenuFacil

Returns a new instance of MenuFacil.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 2

def initialize(name, &block)
  @nombre = name
  @desayuno = []
  @almuerzo = []
  @cena = []
    
  if block_given?  
    if block.arity == 1
      yield self
    else
     instance_eval(&block) 
    end
  end
end

Instance Method Details

#almuerzo(opciones = {}) ⇒ Object



31
32
33
34
35
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 31

def almuerzo(opciones = {})
    ingrediente = []
    ingrediente << opciones[:descripcion] << opciones[:porcion] << opciones[:gramos] << Tabla.new(opciones[:grasas],opciones[:grasasSaturadas],opciones[:carbohidratos],opciones[:azucares],opciones[:proteinas],opciones[:sal])
    @almuerzo << ingrediente
end

#cena(opciones = {}) ⇒ Object



37
38
39
40
41
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 37

def cena(opciones = {})
    ingrediente = []
    ingrediente << opciones[:descripcion] << opciones[:porcion] << opciones[:gramos] << Tabla.new(opciones[:grasas],opciones[:grasasSaturadas],opciones[:carbohidratos],opciones[:azucares],opciones[:proteinas],opciones[:sal])
    @cena << ingrediente
end

#desayuno(opciones = {}) ⇒ Object



25
26
27
28
29
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 25

def desayuno(opciones = {})
    ingrediente = []
    ingrediente << opciones[:descripcion] << opciones[:porcion] << opciones[:gramos] << Tabla.new(opciones[:grasas],opciones[:grasasSaturadas],opciones[:carbohidratos],opciones[:azucares],opciones[:proteinas],opciones[:sal])
    @desayuno << ingrediente
end

#ingesta(ingesta) ⇒ Object



21
22
23
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 21

def ingesta(ingesta)
    @ingesta = ingesta
end

#titulo(titulo) ⇒ Object



17
18
19
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 17

def titulo(titulo)
    @titulo = titulo
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
65
66
67
68
69
70
71
72
73
74
# File 'lib/alu0100406580_nutricion/menuDSL.rb', line 43

def to_s
    output = @nombre
    output << " (#{@titulo}), Ingesta: #{@ingesta}"
    output << "#{' ' * 50} ComposiciĆ³n Nutricional #{' ' * 50}"
    output << "\n#{'=' * 165}\n"
    output << "#{' ' * 35} PorciĆ³n   Gramos #{' ' * 50} Grasas  Grasas-saturadas  Hidratos  Azucares  Proteinas  Sal\n" #58 75 85 95 106 111
    output << "Desayuno\n"
    kcaltotal = 0 
    @desayuno.each_with_index do |instruction, i|
        output << "\"#{instruction[0]}\" #{' ' * (31 - instruction[0].size.to_i)}#{instruction[1]}#{' ' * (15 - instruction[1].size.to_i)}#{instruction[2]}#{' ' * (64 - instruction[2].size.to_i)}#{instruction[3].grasas}#{' ' * 10}#{instruction[3].grasasSat}#{' ' * 12}#{instruction[3].hidratos}#{' ' * 3}#{instruction[3].azucares}#{' ' * 5}#{instruction[3].proteinas}#{' ' * 8}#{instruction[3].sal}\n"
        kcaltotal += instruction[3].valEnerKcal
    end
    output << "\nValor Energetico total desayuno: #{kcaltotal.round(2)}Kcal\n"

    output << "\nAlmuerzo\n"
    kcaltotal = 0 
    @almuerzo.each_with_index do |instruction, i|
        output << "\"#{instruction[0]}\" #{' ' * (31 - instruction[0].size.to_i)}#{instruction[1]}#{' ' * (15 - instruction[1].size.to_i)}#{instruction[2]}#{' ' * (64 - instruction[2].size.to_i)}#{instruction[3].grasas}#{' ' * 10}#{instruction[3].grasasSat}#{' ' * 12}#{instruction[3].hidratos}#{' ' * 3}#{instruction[3].azucares}#{' ' * 5}#{instruction[3].proteinas}#{' ' * 8}#{instruction[3].sal}\n"
        kcaltotal += instruction[3].valEnerKcal
    end
    output << "\nValor Energetico total almuerzo: #{kcaltotal.round(2)}Kcal\n"

    output << "\nCena\n"
    kcaltotal = 0 
    @cena.each_with_index do |instruction, i|
        output << "\"#{instruction[0]}\" #{' ' * (31 - instruction[0].size.to_i)}#{instruction[1]}#{' ' * (15 - instruction[1].size.to_i)}#{instruction[2]}#{' ' * (64 - instruction[2].size.to_i)}#{instruction[3].grasas}#{' ' * 10}#{instruction[3].grasasSat}#{' ' * 12}#{instruction[3].hidratos}#{' ' * 3}#{instruction[3].azucares}#{' ' * 5}#{instruction[3].proteinas}#{' ' * 8}#{instruction[3].sal}\n"
        kcaltotal += instruction[3].valEnerKcal
    end
    output << "\nValor Energetico total cena: #{kcaltotal.round(2)}Kcal\n"
    output

end