Class: MenuDiet
- Inherits:
-
Object
- Object
- MenuDiet
- Defined in:
- lib/practica6/dieta.rb
Instance Attribute Summary collapse
-
#ingesta ⇒ Object
Returns the value of attribute ingesta.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platos ⇒ Object
Returns the value of attribute platos.
-
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
-
#titulo ⇒ Object
Returns the value of attribute titulo.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ MenuDiet
constructor
A new instance of MenuDiet.
- #met_ingesta(options = {}) ⇒ Object
- #met_titulo(name) ⇒ Object
- #plato(options = {}) ⇒ Object
- #porcent(options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ MenuDiet
Returns a new instance of MenuDiet.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/practica6/dieta.rb', line 8 def initialize(name, &block) self.name = name self.titulo = "" self.ingesta = [] self.platos = [] self.porcentajes = [] if block_given? if block.arity == 1 yield self else instance_eval &block end end end |
Instance Attribute Details
#ingesta ⇒ Object
Returns the value of attribute ingesta.
6 7 8 |
# File 'lib/practica6/dieta.rb', line 6 def ingesta @ingesta end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/practica6/dieta.rb', line 6 def name @name end |
#platos ⇒ Object
Returns the value of attribute platos.
6 7 8 |
# File 'lib/practica6/dieta.rb', line 6 def platos @platos end |
#porcentajes ⇒ Object
Returns the value of attribute porcentajes.
6 7 8 |
# File 'lib/practica6/dieta.rb', line 6 def porcentajes @porcentajes end |
#titulo ⇒ Object
Returns the value of attribute titulo.
6 7 8 |
# File 'lib/practica6/dieta.rb', line 6 def titulo @titulo end |
Instance Method Details
#met_ingesta(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/practica6/dieta.rb', line 26 def met_ingesta( = {}) ingest = [] if ([:min] && [:max]) ingest << [:min] ingest << [:max] else ingest << [:max] end ingesta << ingest end |
#met_titulo(name) ⇒ Object
23 24 25 |
# File 'lib/practica6/dieta.rb', line 23 def met_titulo(name) titulo << name end |
#plato(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/practica6/dieta.rb', line 40 def plato( = {}) aux = [] aux << "#{[:descripcion]}" aux << "#{[:porcion]}" aux << "#{[:gramos]}" platos << aux end |
#porcent(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/practica6/dieta.rb', line 49 def porcent( = {}) val = [] val << "#{[:vct]}" val << "#{[:proteinas]}" val << "#{[:grasas]}" val << "#{[:hidratos]}" porcentajes << val end |
#to_s ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/practica6/dieta.rb', line 61 def to_s output = name output << "\n#{'=' * name.size}\n\n" output << "#{titulo} " ingesta.each do |ingest| output << "#{ingest}\n" end platos.each do |aux| output << "- #{aux[0]}, #{aux[1]}, #{aux[2]}g\n" end porcentajes.each do |val| output << "V.C.T. | % #{val[0]} kcal | #{val[1]}% - #{val[2]}% - #{val[3]}%\n" end output end |