Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dia, &block) ⇒ Menu

Returns a new instance of Menu.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/prct06/menu.rb', line 4

def initialize(dia,&block)
	@dia = dia
	@ingesta = []
	@desayuno = []
	@cena = []
	@almuerzo = []

	if block_given?
	  if block.arity == 1
	    yield self
	  else
	    instance_eval(&block)
	  end
	end
end

Instance Attribute Details

#descripcionObject

Returns the value of attribute descripcion.



2
3
4
# File 'lib/prct06/menu.rb', line 2

def descripcion
  @descripcion
end

#diaObject

Returns the value of attribute dia.



2
3
4
# File 'lib/prct06/menu.rb', line 2

def dia
  @dia
end

#ingesta(ing, options = {}) ⇒ Object

Returns the value of attribute ingesta.



2
3
4
# File 'lib/prct06/menu.rb', line 2

def ingesta
  @ingesta
end

#nombreObject

Returns the value of attribute nombre.



2
3
4
# File 'lib/prct06/menu.rb', line 2

def nombre
  @nombre
end

Instance Method Details

#almuerzo(al, options = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/prct06/menu.rb', line 105

def almuerzo(al, options = {})
        lunch = al
        lunch << "(#{options[:descripcion]})" if options[:descripcion]
        lunch << "(#{options[:porcion]})" if options[:porcion]
        lunch << "(#{options[:gramos]})" if options[:gramos]
        lunch << "(#{options[:grasas]})" if options[:grasas]
        lunch << "(#{options[:carbohidratos]})" if options[:carbohidratos]
        lunch << "(#{options[:proteinas]})" if options[:proteinas]
        lunch << "(#{options[:fibra]})" if options[:fibra]
        lunch << "(#{options[:sal]})" if options[:sal]

        @almuerzo << lunch
end

#cena(ce, options = {}) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/prct06/menu.rb', line 119

def cena(ce, options = {})
        din = ce 
        din << "(#{options[:descripcion]})" if options[:descripcion]
        din << "(#{options[:porcion]})" if options[:porcion]
        din << "(#{options[:gramos]})" if options[:gramos]
        din << "(#{options[:grasas]})" if options[:grasas]
        din << "(#{options[:carbohidratos]})" if options[:carbohidratos]
        din << "(#{options[:proteinas]})" if options[:proteinas]
        din << "(#{options[:fibra]})" if options[:fibra]
        din << "(#{options[:sal]})" if options[:sal]

        @cena << din
end

#desayuno(des, options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/prct06/menu.rb', line 91

def desayuno(des, options = {})
	bf = des
	bf << "(#{options[:descripcion]})" if options[:descripcion]
	bf << "(#{options[:porcion]})" if options[:porcion]
	bf << "(#{options[:gramos]})" if options[:gramos]
	bf << "(#{options[:grasas]})" if options[:grasas]
	bf << "(#{options[:carbohidratos]})" if options[:carbohidratos]
	bf << "(#{options[:proteinas]})" if options[:proteinas]
	bf << "(#{options[:fibra]})" if options[:fibra]
	bf << "(#{options[:sal]})" if options[:sal]

	@desayuno << bf
end

#titulo(nom) ⇒ Object



79
80
81
# File 'lib/prct06/menu.rb', line 79

def titulo(nom)
	nombr = nom
end

#to_sObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
# File 'lib/prct06/menu.rb', line 20

def to_s
	vet = 0
	output = @dia
	output << "                          Composición Nutricional\n"
	output << "===========================================================\n"
	output << "                          grasas  carbohidratos  proteínas  fibra  sal  valor energético\n"
	output << "Desayuno\n"
	@desayuno.each do |alimento|
		vet += valor_energetico(alimento)
		output << "*#{alimento[:descripcion]}*      "
		output << "#{alimento[:grasas]}        "
		output << "#{alimento[:carbohidratos]}        "
		output << "#{alimento[:proteinas]}        "
		output << "#{alimento[:fibra]}     "
		output << "#{alimento[:sal]}    "
		output << "#{valor_energetico(alimento)}\n"
		 
	end

	output << "\nAlmuerzo\n"
	@almuerzo.each do |alimento|
		vet += valor_energetico(alimento)
		output << "*#{alimento[:descripcion]}*            "
                       output << "#{alimento[:grasas]}          "
                       output << "#{alimento[:carbohidratos]}        "
                       output << "#{alimento[:proteinas]}        "
                       output << "#{alimento[:fibra]}        "
                       output << "#{alimento[:sal]}        "
		output << "#{valor_energetico(alimento)}\n"

	end
	
	output << "\nCena\n"
	@cena.each do |alimento|
		vet += valor_energetico(alimento)
                       output << "*#{alimento[:descripcion]}*  "
                       output << "#{alimento[:grasas]}      "
                       output << "#{alimento[:carbohidratos]}     "
                       output << "#{alimento[:proteinas]}       "
                       output << "#{alimento[:fibra]}      "
                       output << "#{alimento[:sal]}      "
		output << "#{valor_energetico(alimento)}\n"

               end

	output << "Valor energético total   "
	output << "#{vet}"


	output
end

#valor_energetico(comida) ⇒ Object



72
73
74
75
76
77
# File 'lib/prct06/menu.rb', line 72

def valor_energetico(comida)
	kcal = comida[:grasas] * 0.9
	kcal += comida[:carbohidratos] * 0.4
	kcal += comida[:proteinas] * 0.4
	  kcal.round(2)
end