Class: Gema6::Dieta
Overview
Clase que representa una Dieta (menú dietético)
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 ⇒ Object
readonly
Returns the value of attribute porcentaje.
-
#porcentaje_max ⇒ Object
readonly
Returns the value of attribute porcentaje_max.
-
#porcentaje_min ⇒ Object
readonly
Returns the value of attribute porcentaje_min.
-
#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
-
#<=>(otro) ⇒ Object
Método utilizado para comparar un menú con otro.
-
#getCjtoPlatos(i, k) ⇒ Object
Devuelve un array (conjunto) de platos especificado por parámetro.
-
#getDescripcion(i) ⇒ Object
Devuelve la descripción completa del plato indicado por parámetro.
-
#getGramos(i) ⇒ Object
Devuelve los gramos que contiene el plato indicado por parámetro.
-
#getPlato(i) ⇒ Object
Devuelve el plato indicado por parámetro.
-
#getPorcion(i) ⇒ Object
Devuelve la porción que conlleva el plato indicado por parámetro.
- #ingesta(options = {}) ⇒ Object
-
#initialize(titulo, porcentaje = nil, platos = [], vct = nil, proteinas = nil, grasas = nil, hidratos = nil, &block) ⇒ Dieta
constructor
A new instance of Dieta.
- #plato(options = {}) ⇒ Object
- #porcentajes(options = {}) ⇒ Object
-
#to_s ⇒ Object
Devuelve una cadena que contiene la descripción completa del menú dietético.
Constructor Details
#initialize(titulo, porcentaje = nil, platos = [], vct = nil, proteinas = nil, grasas = nil, hidratos = nil, &block) ⇒ Dieta
Returns a new instance of Dieta.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gema6/dieta.rb', line 7 def initialize(titulo, porcentaje = nil, platos = [], vct = nil, proteinas = nil, grasas = nil, hidratos = nil, &block) @titulo = titulo @porcentaje = porcentaje @platos = platos @vct = vct @proteinas = proteinas @grasas = grasas @hidratos = hidratos if (block_given?) instance_eval &block end end |
Instance Attribute Details
#grasas ⇒ Object (readonly)
Returns the value of attribute grasas.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def grasas @grasas end |
#hidratos ⇒ Object (readonly)
Returns the value of attribute hidratos.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def hidratos @hidratos end |
#platos ⇒ Object (readonly)
Returns the value of attribute platos.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def platos @platos end |
#porcentaje ⇒ Object (readonly)
Returns the value of attribute porcentaje.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def porcentaje @porcentaje end |
#porcentaje_max ⇒ Object (readonly)
Returns the value of attribute porcentaje_max.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def porcentaje_max @porcentaje_max end |
#porcentaje_min ⇒ Object (readonly)
Returns the value of attribute porcentaje_min.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def porcentaje_min @porcentaje_min end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def proteinas @proteinas end |
#titulo ⇒ Object (readonly)
Returns the value of attribute titulo.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def titulo @titulo end |
#vct ⇒ Object (readonly)
Returns the value of attribute vct.
6 7 8 |
# File 'lib/gema6/dieta.rb', line 6 def vct @vct end |
Instance Method Details
#<=>(otro) ⇒ Object
Método utilizado para comparar un menú con otro.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gema6/dieta.rb', line 63 def <=>(otro) #Cuando comparo un menú con otro, pruebo con el VCT, sino lo miramos segun la grasa, luego proteinas, y por ultimo los hidratos. if @vct < otro.vct -1 elsif @vct > otro.vct 1 else # Si son iguales en VCT, mirar grasas... if @grasas < otro.grasas -1 elsif @grasas > otro.grasas 1 else # Si son iguales en grasas, mirar en proteinas if @proteinas < otro.proteinas -1 elsif @proteinas > otro.proteinas 1 else if @hidratos < otro.hidratos -1 elsif @hidratos > otro.hidratos 1 else # SON IGUALES 0 end end end end end |
#getCjtoPlatos(i, k) ⇒ Object
Devuelve un array (conjunto) de platos especificado por parámetro.
32 33 34 35 36 37 38 |
# File 'lib/gema6/dieta.rb', line 32 def getCjtoPlatos(i, k) @cjto = [] for p in i..k @cjto.push(@platos.at(p)) end @cjto end |
#getDescripcion(i) ⇒ Object
Devuelve la descripción completa del plato indicado por parámetro
22 23 24 |
# File 'lib/gema6/dieta.rb', line 22 def getDescripcion(i) @platos.at(i).at(0) end |
#getGramos(i) ⇒ Object
Devuelve los gramos que contiene el plato indicado por parámetro.
46 47 48 |
# File 'lib/gema6/dieta.rb', line 46 def getGramos(i) getPlato(i).at(2) end |
#getPlato(i) ⇒ Object
Devuelve el plato indicado por parámetro
27 28 29 |
# File 'lib/gema6/dieta.rb', line 27 def getPlato(i) @platos.at(i) end |
#getPorcion(i) ⇒ Object
Devuelve la porción que conlleva el plato indicado por parámetro.
41 42 43 |
# File 'lib/gema6/dieta.rb', line 41 def getPorcion(i) getPlato(i).at(1) end |
#ingesta(options = {}) ⇒ Object
96 97 98 99 |
# File 'lib/gema6/dieta.rb', line 96 def ingesta( = {}) @porcentaje_min = [:min] @porcentaje_max = [:max] end |
#plato(options = {}) ⇒ Object
101 102 103 104 |
# File 'lib/gema6/dieta.rb', line 101 def plato( = {}) plato = [[:descripcion], [:porcion], [:gramos]] @platos.push(plato) end |
#porcentajes(options = {}) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/gema6/dieta.rb', line 106 def porcentajes( = {}) @vct = [:vct] @proteinas = [:proteinas] @grasas = [:grasas] @hidratos = [:hidratos] end |
#to_s ⇒ Object
Devuelve una cadena que contiene la descripción completa del menú dietético.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gema6/dieta.rb', line 51 def to_s @resultado = "#{@titulo} (#{@porcentaje}%)\n" for p in 0..(@platos.length - 1) @resultado.concat("- #{getDescripcion(p)}, #{getPorcion(p)}, #{getGramos(p)} g \n") end @resultado.concat("V.C.T. | %\t#{@vct} kcal | #{@proteinas}% - #{@grasas}% - #{@hidratos}%") @resultado end |