Class: DietaNueva_t
- Inherits:
-
Object
- Object
- DietaNueva_t
- Defined in:
- lib/prct06/diet.rb
Instance Attribute Summary collapse
-
#platos ⇒ Object
Returns the value of attribute platos.
-
#porcediarios ⇒ Object
Returns the value of attribute porcediarios.
-
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
-
#titulo ⇒ Object
Returns the value of attribute titulo.
Instance Method Summary collapse
-
#initialize(titulo, &block) ⇒ DietaNueva_t
constructor
A new instance of DietaNueva_t.
- #plato(options = {}) ⇒ Object
- #porcediario(options = {}) ⇒ Object
- #porcentaje(options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(titulo, &block) ⇒ DietaNueva_t
Returns a new instance of DietaNueva_t.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/prct06/diet.rb', line 7 def initialize(titulo, &block) self.titulo = titulo self.porcediarios = [] self.platos = [] self.porcentajes = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#platos ⇒ Object
Returns the value of attribute platos.
5 6 7 |
# File 'lib/prct06/diet.rb', line 5 def platos @platos end |
#porcediarios ⇒ Object
Returns the value of attribute porcediarios.
5 6 7 |
# File 'lib/prct06/diet.rb', line 5 def porcediarios @porcediarios end |
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
5 6 7 |
# File 'lib/prct06/diet.rb', line 5 def porcentajes @porcentajes end |
#titulo ⇒ Object
Returns the value of attribute titulo.
5 6 7 |
# File 'lib/prct06/diet.rb', line 5 def titulo @titulo end |
Instance Method Details
#plato(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/prct06/diet.rb', line 49 def plato( = {}) plato = " #{options[:descripcion]}." if [:descripcion] plato += " #{options[:porciones]}." if [:porciones] plato += " #{options[:ingengr]}.\n" if [:ingengr] platos << plato end |
#porcediario(options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/prct06/diet.rb', line 44 def porcediario( = {}) porcediarios << "\nMin: #{options[:minimo]}" if [:minimo] porcediarios << "\nMax: #{options[:maximo]}\n\n" if [:maximo] end |
#porcentaje(options = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/prct06/diet.rb', line 59 def porcentaje( = {}) porcentajes << "#{options[:vct]} kcal" if [:vct] porcentajes << "#{options[:porcproteinas]}%" if [:porcproteinas] porcentajes << "#{options[:porcgrasas]}%" if [:porcgrasas] porcentajes << "#{options[:porchidratos]}%." if [:porchidratos] end |
#to_s ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prct06/diet.rb', line 22 def to_s mostrar = titulo mostrar << "\n#{'=' * titulo.size}\n" mostrar << "\nPorcentajes recomendados de ingesta." porcediarios.each do |porcediario| mostrar << "#{porcediario}" end platos.each_with_index do |plato, i| mostrar << "#{i + 1} #{plato}" end mostrar << "\nV.C.T. y porcentajes: " porcentajes.each do |porcentaje| mostrar << " #{porcentaje}" end mostrar << "\n\n" end |