Class: Platos

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

Overview

Clase Platos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(titulo, &block) ⇒ Platos

Returns a new instance of Platos.



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

def initialize(titulo,&block)
	@titulo = titulo
   		@vegetal = []
   		@fruta = []
   		@proteina = []
   		@aceite = []
	@cereal= []
	@agua=[]
	if block_given?  
		if block.arity == 1
			yield self
		else
			instance_eval(&block) 
		end
	end
end

Instance Attribute Details

#glucidosObject

Returns the value of attribute glucidos.



4
5
6
# File 'lib/gema/platos.rb', line 4

def glucidos
  @glucidos
end

#lipidosObject

Returns the value of attribute lipidos.



4
5
6
# File 'lib/gema/platos.rb', line 4

def lipidos
  @lipidos
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/gema/platos.rb', line 4

def name
  @name
end

#proteinasObject

Returns the value of attribute proteinas.



4
5
6
# File 'lib/gema/platos.rb', line 4

def proteinas
  @proteinas
end

#tituloObject

Returns the value of attribute titulo.



4
5
6
# File 'lib/gema/platos.rb', line 4

def titulo
  @titulo
end

Instance Method Details

#aceite_(name = "", opciones = {}) ⇒ Object



101
102
103
104
105
106
# File 'lib/gema/platos.rb', line 101

def aceite_(name= "",opciones={})
	porcion=""
	porcion = opciones[:porcion] if opciones[:porcion]
	@aceite.push([name,porcion]) 

end

#agua_(name = "", opciones = {}) ⇒ Object



107
108
109
110
111
112
# File 'lib/gema/platos.rb', line 107

def agua_(name= "",opciones={})
	porcion=""
	porcion = opciones[:porcion] if opciones[:porcion]
	@agua.push([name,porcion]) 

end

#cereal_(name = "", opciones = {}) ⇒ Object



89
90
91
92
93
94
# File 'lib/gema/platos.rb', line 89

def cereal_(name= "",opciones={})
	porcion=""
	porcion = opciones[:porcion] if opciones[:porcion]
	@cereal.push([name,porcion]) 

end

#fruta_(name = "", opciones = {}) ⇒ Object



83
84
85
86
87
88
# File 'lib/gema/platos.rb', line 83

def fruta_(name= "",opciones={})
	gramos=""
	gramos = opciones[:gramos] if opciones[:gramos]
	@fruta.push([name,gramos]) 

end

#proteina_(name = "", opciones = {}) ⇒ Object



95
96
97
98
99
100
# File 'lib/gema/platos.rb', line 95

def proteina_(name= "",opciones={})
	porcion=""
	porcion = opciones[:porcion] if opciones[:porcion]
	@proteina.push([name,porcion]) 

end

#to_sObject



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
71
72
73
74
75
76
# File 'lib/gema/platos.rb', line 21

def to_s
	output = "\n#{@titulo}"
	output << "\n============================================\n"
	output << "Composición nutricional:\n\n"
	output << "\t\tglúcidos proteínas lípidos valor energético\n\n" 
	valor_total=0
	for i in 0..self.vegetal_.size-1 
				ARRAY.each_with_index do |array, index|          
			if self.vegetal_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.vegetal_[i][1].to_f}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.vegetal_[i][1].to_f
			end
		end
	end
	for i in 0..self.fruta_.size-1 
		ARRAY.each_with_index do |array, index|          
			if self.fruta_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.fruta_[i][1]*0.1}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.fruta_[i][1]*0.1
			end
		end
	end
	for i in 0..self.cereal_.size-1 
		ARRAY.each_with_index do |array, index|          
			if self.cereal_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.cereal_[i][1].to_f}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.cereal_[i][1].to_f
			end
		end
	end
	for i in 0..self.proteina_.size-1 
		ARRAY.each_with_index do |array, index|          
			if self.proteina_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.proteina_[i][1].to_f}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.proteina_[i][1].to_f
			end
		end
	end
	for i in 0..self.aceite_.size-1 
		ARRAY.each_with_index do |array, index|          
			if self.aceite_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.aceite_[i][1].to_f}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.aceite_[i][1].to_f
			end
		end
	end
	for i in 0..self.agua_.size-1 
		ARRAY.each_with_index do |array, index|          
			if self.agua_[i][0] == ARRAY[index].get_name
				output << "#{ARRAY[index].get_name}\t#{ARRAY[index].get_proteinas}\t #{ARRAY[index].get_glucidos}\t   #{ARRAY[index].get_grasas}\t   #{ARRAY[index].get_valor_energetico*self.agua_[i][1].to_f}\n"
				valor_total+=ARRAY[index].get_valor_energetico*self.agua_[i][1].to_f
			end
		end
	end
	output << "\nValor energético total\t\t\t   #{valor_total}"
end

#vegetal_(name = "", opciones = {}) ⇒ Object



77
78
79
80
81
82
# File 'lib/gema/platos.rb', line 77

def vegetal_(name= "", opciones={})
	porcion=""
	porcion = opciones[:porcion] if opciones[:porcion]
	@vegetal.push([name,porcion]) 

end