Class: DietaDSL
Instance Attribute Summary collapse
-
#ingestas ⇒ Object
Returns the value of attribute ingestas.
-
#platos ⇒ Object
Returns the value of attribute platos.
-
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
-
#salida ⇒ Object
Returns the value of attribute salida.
-
#titulos ⇒ Object
Returns the value of attribute titulos.
Attributes inherited from Diet
#calorias, #comida, #porciones
Instance Method Summary collapse
- #ingesta(opciones = {}) ⇒ Object
-
#initialize(name, &block) ⇒ DietaDSL
constructor
A new instance of DietaDSL.
- #plato(opciones = {}) ⇒ Object
- #porcentaje(opciones = {}) ⇒ Object
- #titulo(name) ⇒ Object
- #to_s ⇒ Object
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
#ingestas ⇒ Object
Returns the value of attribute ingestas.
2 3 4 |
# File 'lib/dieta/dieta_dsl.rb', line 2 def ingestas @ingestas end |
#platos ⇒ Object
Returns the value of attribute platos.
2 3 4 |
# File 'lib/dieta/dieta_dsl.rb', line 2 def platos @platos end |
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
2 3 4 |
# File 'lib/dieta/dieta_dsl.rb', line 2 def porcentajes @porcentajes end |
#salida ⇒ Object
Returns the value of attribute salida.
2 3 4 |
# File 'lib/dieta/dieta_dsl.rb', line 2 def salida @salida end |
#titulos ⇒ Object
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_s ⇒ Object
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 |