Class: Dieta
Overview
Clase dieta base. Almacena un menú, indicando aspectos, tales como, porcentaje de ingesta, VCT, proteínas, grasas, hidratos y los platos
Direct Known Subclasses
Instance Attribute Summary collapse
-
#grasas ⇒ Object
readonly
Returns the value of attribute grasas.
-
#hidratos ⇒ Object
readonly
Returns the value of attribute hidratos.
-
#platos ⇒ Object
readonly
Returns the value of attribute platos.
-
#porcentaje_ingesta ⇒ Object
readonly
Returns the value of attribute porcentaje_ingesta.
-
#proteinas ⇒ Object
readonly
Returns the value of attribute proteinas.
-
#titulo ⇒ Object
readonly
Returns the value of attribute titulo.
-
#VCT ⇒ Object
readonly
Returns the value of attribute VCT.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #ingesta(options = {}) ⇒ Object
-
#initialize(titulo = 0, porcentaje_ingesta = 0, nplatos = 0, vct = 0, proteinas = 0, grasas = 0, hidratos = 0, *des_platos, &block) ⇒ Dieta
constructor
constructor.
- #nplatos ⇒ Object
- #plate(options = {}) ⇒ Object
- #plato(n) ⇒ Object
- #porcentajes(options = {}) ⇒ Object
- #title(name) ⇒ Object
-
#to_s ⇒ Object
Muestra el menú correctamente formateado.
Constructor Details
#initialize(titulo = 0, porcentaje_ingesta = 0, nplatos = 0, vct = 0, proteinas = 0, grasas = 0, hidratos = 0, *des_platos, &block) ⇒ Dieta
constructor
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prct06/Dieta.rb', line 9 def initialize (titulo=0, porcentaje_ingesta=0, nplatos=0, vct=0, proteinas=0, grasas=0, hidratos=0, *des_platos, &block) @name = titulo @platos = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end else @titulo = titulo @porcentaje_ingesta = porcentaje_ingesta @nplatos = nplatos @platos = [] for i in 0..nplatos-1 do aux = [des_platos[i][0], des_platos[i][1], des_platos[i][2]] @platos.push(aux) end @VCT = vct @proteinas = proteinas @grasas = grasas @hidratos = hidratos end end |
Instance Attribute Details
#grasas ⇒ Object (readonly)
Returns the value of attribute grasas.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def grasas @grasas end |
#hidratos ⇒ Object (readonly)
Returns the value of attribute hidratos.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def hidratos @hidratos end |
#platos ⇒ Object (readonly)
Returns the value of attribute platos.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def platos @platos end |
#porcentaje_ingesta ⇒ Object (readonly)
Returns the value of attribute porcentaje_ingesta.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def porcentaje_ingesta @porcentaje_ingesta end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def proteinas @proteinas end |
#titulo ⇒ Object (readonly)
Returns the value of attribute titulo.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def titulo @titulo end |
#VCT ⇒ Object (readonly)
Returns the value of attribute VCT.
5 6 7 |
# File 'lib/prct06/Dieta.rb', line 5 def VCT @VCT end |
Instance Method Details
#<=>(other) ⇒ Object
67 68 69 |
# File 'lib/prct06/Dieta.rb', line 67 def <=> (other) @VCT <=> other.VCT end |
#ingesta(options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/prct06/Dieta.rb', line 45 def ingesta( = {}) @porcentaje_ingesta = "#{[:min]}-#{[:max]}" end |
#nplatos ⇒ Object
62 63 64 |
# File 'lib/prct06/Dieta.rb', line 62 def nplatos @platos.length end |
#plate(options = {}) ⇒ Object
51 52 53 |
# File 'lib/prct06/Dieta.rb', line 51 def plate( = {}) @platos << ["#{[:descripcion]}", "#{[:porcion]}", [:gramos]] end |
#plato(n) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/prct06/Dieta.rb', line 71 def plato (n) if n > @platos.length || n < 1 then return "" end return @platos[n-1] end |
#porcentajes(options = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/prct06/Dieta.rb', line 55 def porcentajes( = {}) @VCT = [:vct] if [:vct] @proteinas = [:proteinas] if [:proteinas] @grasas = [:grasas] if [:grasas] @hidratos = [:hidratos] if [:hidratos] end |
#title(name) ⇒ Object
39 40 41 42 43 |
# File 'lib/prct06/Dieta.rb', line 39 def title(name) @titulo = name end |
#to_s ⇒ Object
Muestra el menú correctamente formateado
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/prct06/Dieta.rb', line 79 def to_s x = "" x << "#{@titulo} (#{@porcentaje_ingesta}%)\n" @platos.each do |i| x << "- #{i[0]}, #{i[1]}, #{i[2]}g\n" end x << "V.C.T | % #{@VCT} kcal | #{@proteinas} #{@grasas} #{@hidratos}" end |