Class: DietaDSL

Inherits:
Diet
  • Object
show all
Defined in:
lib/dieta/dieta_dsl.rb

Instance Attribute Summary collapse

Attributes inherited from Diet

#calorias, #comida, #porciones

Instance Method Summary collapse

Methods inherited from Diet

#<=>, #==, #calorias_to_s, #comida_to_s, #porciones_to_s

Constructor Details

#initialize(name, &block) ⇒ DietaDSL

Returns a new instance of DietaDSL.



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

def initialize(name,&block)
	self.titulos=[]
	self.ingestas=[]
	self.platos=[]
	self.porcentajes=[]

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

Instance Attribute Details

#ingestasObject

Returns the value of attribute ingestas.



2
3
4
# File 'lib/dieta/dieta_dsl.rb', line 2

def ingestas
  @ingestas
end

#platosObject

Returns the value of attribute platos.



2
3
4
# File 'lib/dieta/dieta_dsl.rb', line 2

def platos
  @platos
end

#porcentajesObject

Returns the value of attribute porcentajes.



2
3
4
# File 'lib/dieta/dieta_dsl.rb', line 2

def porcentajes
  @porcentajes
end

#salidaObject

Returns the value of attribute salida.



2
3
4
# File 'lib/dieta/dieta_dsl.rb', line 2

def salida
  @salida
end

#titulosObject

Returns the value of attribute titulos.



2
3
4
# File 'lib/dieta/dieta_dsl.rb', line 2

def titulos
  @titulos
end

Instance Method Details

#ingesta(opciones = {}) ⇒ Object



23
24
25
26
# File 'lib/dieta/dieta_dsl.rb', line 23

def ingesta(opciones ={})
	ingestas << "#{opciones[:min]}" if opciones[:min]
	ingestas << "#{opciones[:max]}" if opciones[:max]
end

#plato(opciones = {}) ⇒ Object



28
29
30
31
32
# File 'lib/dieta/dieta_dsl.rb', line 28

def plato(opciones= {})
	platos << "#{opciones[:descripcion]}" if opciones[:descripcion]
	platos << "#{opciones[:porcion]}" if opciones[:porcion]
	platos << "#{opciones[:gramos]}" if opciones[:gramos]
end

#porcentaje(opciones = {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/dieta/dieta_dsl.rb', line 34

def porcentaje(opciones={})
	porcentajes << "#{opciones[:vct]}" if opciones[:vct]
	porcentajes << "#{opciones[:proteinas]}" if opciones[:proteinas]
	porcentajes << "#{opciones[:grasas]}" if opciones[:grasas]
	porcentajes << "#{opciones[:hidratos]}" if opciones[:hidratos]
end

#titulo(name) ⇒ Object



19
20
21
# File 'lib/dieta/dieta_dsl.rb', line 19

def titulo(name)
	titulos << name
end

#to_sObject



41
42
43
44
45
46
47
48
49
# File 'lib/dieta/dieta_dsl.rb', line 41

def to_s
	salida = titulos
	        salida << "(#{ingestas[0]}% - #{ingestas[1]}%)"
	        platos.each_with_index do |plato|
	            salida << "#{plato}"
	        end
	        salida << "V.C.T. | % #{porcentajes[0]} Kcal | #{porcentajes[1]}% - #{porcentajes[2]}% - #{porcentajes[3]}%"
	        salida
end