Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dia, &block) ⇒ Menu

Returns a new instance of Menu.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/Menu.rb', line 5

def initialize(dia, &block)
    @dia = dia
    @titulo_menu = nil
    @tiempo_comida = []
    @desayunos = []
    @comidas = []
    @cenas = []
    @val_ener = nil
    @vet = 0
    
    if block_given?  
        if block.arity == 1
            yield self
        else
            instance_eval(&block) 
        end
    end
end

Instance Attribute Details

#cenasObject

Returns the value of attribute cenas.



3
4
5
# File 'lib/Menu.rb', line 3

def cenas
  @cenas
end

#comidasObject

Returns the value of attribute comidas.



3
4
5
# File 'lib/Menu.rb', line 3

def comidas
  @comidas
end

#desayunosObject

Returns the value of attribute desayunos.



3
4
5
# File 'lib/Menu.rb', line 3

def desayunos
  @desayunos
end

#diaObject

Returns the value of attribute dia.



3
4
5
# File 'lib/Menu.rb', line 3

def dia
  @dia
end

#tiempo_comidaObject

Returns the value of attribute tiempo_comida.



3
4
5
# File 'lib/Menu.rb', line 3

def tiempo_comida
  @tiempo_comida
end

#titulo_menuObject

Returns the value of attribute titulo_menu.



3
4
5
# File 'lib/Menu.rb', line 3

def titulo_menu
  @titulo_menu
end

#val_enerObject

Returns the value of attribute val_ener.



3
4
5
# File 'lib/Menu.rb', line 3

def val_ener
  @val_ener
end

#vetObject

Returns the value of attribute vet.



3
4
5
# File 'lib/Menu.rb', line 3

def vet
  @vet
end

Instance Method Details

#cena(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/Menu.rb', line 78

def cena(options = {})
    dinner = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
    dinner << sprintf(" %-15s", "#{options[:porcion]}")
    dinner << sprintf(" %-10s", "#{options[:gramos]}")
    dinner << sprintf(" %-10s", "#{options[:grasas]}")
    dinner << sprintf(" %-15s", "#{options[:carbohidratos]}")
    dinner << sprintf(" %-12s", "#{options[:proteinas]}")
    dinner << sprintf(" %-8s", " #{options[:fibra]}")
    dinner << sprintf(" %-7s", "#{options[:sal]}")
    
    valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
    dinner << sprintf(" %-10s", "#{@val_ener}")
    
    @cenas << dinner
end

#comida(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/Menu.rb', line 62

def comida(options = {})
    meal = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
    meal << sprintf(" %-15s", "#{options[:porcion]}")
    meal << sprintf(" %-10s", "#{options[:gramos]}")
    meal << sprintf(" %-10s", "#{options[:grasas]}")
    meal << sprintf(" %-15s", "#{options[:carbohidratos]}")
    meal << sprintf(" %-12s", "#{options[:proteinas]}")
    meal << sprintf(" %-8s", " #{options[:fibra]}")
    meal << sprintf(" %-7s", "#{options[:sal]}")
    
    valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
    meal << sprintf(" %-10s", "#{@val_ener}")
    
    @comidas << meal
end

#desayuno(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/Menu.rb', line 46

def desayuno(options = {})
    breakfast = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
    breakfast << sprintf(" %-15s", "#{options[:porcion]}")
    breakfast << sprintf(" %-10s", "#{options[:gramos]}")
    breakfast << sprintf(" %-10s", "#{options[:grasas]}")
    breakfast << sprintf(" %-15s", "#{options[:carbohidratos]}")
    breakfast << sprintf(" %-12s", "#{options[:proteinas]}")
    breakfast << sprintf(" %-8s", " #{options[:fibra]}")
    breakfast << sprintf(" %-7s", "#{options[:sal]}")
    
    valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
    breakfast << sprintf(" %-10s", "#{@val_ener}")
    
    @desayunos << breakfast
end

#ingesta(options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/Menu.rb', line 39

def ingesta(options = {})
    time = " #{options[:min]}" if options[:min]
    time << " #{options[:max]}" if options[:max]
    
    @tiempo_comida << time
end

#printmObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/Menu.rb', line 122

def printm
    cout = "\n" + @dia + "     " + @titulo_menu + "                 Composicion nutricional"
    cout << "\n#{'=' * cout.size}\n"
    
    header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico")

    cout << header
    cout << "Desayuno\n"
    @desayunos.each do |aux|
      cout << "#{aux}\n"
    end
    
    cout << "\ncomida\n"
    @comidas.each do |aux2|
      cout << "#{aux2}\n"
    end
    
    cout << "\ncena\n"
    @cenas.each do |aux3|
      cout << "#{aux3}\n"
    end
    
    cout << "\nvalor energetico total #{@vet.round(2)}" + "\n"
    puts cout
end

#titulo(nombre) ⇒ Object



24
25
26
# File 'lib/Menu.rb', line 24

def titulo(nombre)
  @titulo_menu = nombre
end

#to_sObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/Menu.rb', line 94

def to_s
   
    cout = "\n" + @dia + "     " + @titulo_menu + "                 Composicion nutricional"
    cout << "\n#{'=' * cout.size}\n"
    
    header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico")

    cout << header
    cout << "Desayuno\n"
    @desayunos.each do |aux|
      cout << "#{aux}\n"
    end
    
    cout << "\ncomida\n"
    @comidas.each do |aux2|
      cout << "#{aux2}\n"
    end
    
    cout << "\ncena\n"
    @cenas.each do |aux3|
      cout << "#{aux3}\n"
    end
    
    cout << "\nvalor energetico total #{@vet.round(2)}" + "\n"
    cout
   
end

#valor_energetico(grasas, carbohidratos, proteinas, fibra, sal) ⇒ Object



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

def valor_energetico(grasas, carbohidratos, proteinas, fibra, sal)
    if grasas == nil then grasas = 0 end
    if carbohidratos == nil then carbohidratos = 0 end
    if proteinas == nil then proteinas = 0 end
    if fibra == nil then fibra = 0 end
    if sal == nil then sal = 0 end
        
    @val_ener = (grasas * 9) + (carbohidratos * 4) + (proteinas * 4) + (fibra * 4) + (sal * 6)
    @vet += @val_ener
end