Class: Dieta
Overview
Clase que contiene un menú
Instance Attribute Summary collapse
-
#cantidad ⇒ Object
Returns the value of attribute cantidad.
-
#descripcion ⇒ Object
Returns the value of attribute descripcion.
-
#ingesta ⇒ Object
Returns the value of attribute ingesta.
-
#kcal ⇒ Object
Returns the value of attribute kcal.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#racion ⇒ Object
Returns the value of attribute racion.
-
#tipo_dieta ⇒ Object
Returns the value of attribute tipo_dieta.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparacion.
- #==(other) ⇒ Object
-
#get_descripcion(pos) ⇒ Object
devuelve el nombre del plato especificado en “pos”.
-
#get_gras ⇒ Object
devuelve porcentaje de grasas.
-
#get_hidr ⇒ Object
devuelve porcentaje de hidratos.
-
#get_platos ⇒ Object
devuelve todos los platos que hay con sus descripciones.
-
#get_prot ⇒ Object
devuelve porcentajes de proteinas.
-
#get_titulo ⇒ Object
devuelve el tipo de comida mas su ingesta diaria.
-
#get_to_(pos) ⇒ Object
devuelve una linea con la descripcion completa de un plato.
-
#initialize(tipo_dieta, ingesta, descripcion, racion, cantidad, kcal, percent) ⇒ Dieta
constructor
A new instance of Dieta.
-
#to_s ⇒ Object
devuelve la salida con todos los datos.
Constructor Details
#initialize(tipo_dieta, ingesta, descripcion, racion, cantidad, kcal, percent) ⇒ Dieta
Returns a new instance of Dieta
4 5 6 7 8 9 10 11 12 |
# File 'lib/pract07/Dieta.rb', line 4 def initialize(tipo_dieta, ingesta, descripcion, racion, cantidad, kcal, percent) @tipo_dieta = tipo_dieta #Tipo de menu: almuerzo, desayuno... @ingesta = ingesta #porcentaje que representa la ingesta diaria @descripcion = descripcion #descripcion del menu @racion = racion #array de arrays que contienen la porcion de comida que lleva cada plato @cantidad = cantidad #cantidad generalmente en gramos de comida @kcal = kcal # V.C.T del menu @percent = percent #array de porcentajes que muestran: proteinas, grasas e hidratos por menu end |
Instance Attribute Details
#cantidad ⇒ Object
Returns the value of attribute cantidad
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def cantidad @cantidad end |
#descripcion ⇒ Object
Returns the value of attribute descripcion
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def descripcion @descripcion end |
#ingesta ⇒ Object
Returns the value of attribute ingesta
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def ingesta @ingesta end |
#kcal ⇒ Object
Returns the value of attribute kcal
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def kcal @kcal end |
#percent ⇒ Object
Returns the value of attribute percent
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def percent @percent end |
#racion ⇒ Object
Returns the value of attribute racion
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def racion @racion end |
#tipo_dieta ⇒ Object
Returns the value of attribute tipo_dieta
3 4 5 |
# File 'lib/pract07/Dieta.rb', line 3 def tipo_dieta @tipo_dieta end |
Instance Method Details
#<=>(other) ⇒ Object
Comparacion
99 100 101 |
# File 'lib/pract07/Dieta.rb', line 99 def <=>(other) @kcal <=> other.kcal end |
#==(other) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/pract07/Dieta.rb', line 103 def ==(other) if @kcal == other.kcal && @percent == other.percent return true else return false end end |
#get_descripcion(pos) ⇒ Object
devuelve el nombre del plato especificado en “pos”
51 52 53 54 |
# File 'lib/pract07/Dieta.rb', line 51 def get_descripcion(pos) #devuelve el nombre del plato especificado en "pos" s = "#{@descripcion[pos]}" s #se devuelve e imprime end |
#get_gras ⇒ Object
devuelve porcentaje de grasas
33 34 35 |
# File 'lib/pract07/Dieta.rb', line 33 def get_gras #devuelve porcentaje de grasas @percent[1] end |
#get_hidr ⇒ Object
devuelve porcentaje de hidratos
37 38 39 |
# File 'lib/pract07/Dieta.rb', line 37 def get_hidr #devuelve porcentaje de hidratos @percent[2] end |
#get_platos ⇒ Object
devuelve todos los platos que hay con sus descripciones
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pract07/Dieta.rb', line 14 def get_platos #devuelve todos los platos que hay con sus descripciones @i=0 s= "" while (@descripcion[@i] != nil && @cantidad[@i] != nil) do s += "- #{@descripcion[@i]}, " if (@racion[@i] != nil) s += "#{@racion[@i]}, " end s += "#{@cantidad[@i]} g" s += "\n" @i += 1 end s #se devuelve e imprime end |
#get_prot ⇒ Object
devuelve porcentajes de proteinas
29 30 31 |
# File 'lib/pract07/Dieta.rb', line 29 def get_prot #devuelve porcentajes de proteinas @percent[0] end |
#get_titulo ⇒ Object
devuelve el tipo de comida mas su ingesta diaria
41 42 43 44 45 46 47 48 49 |
# File 'lib/pract07/Dieta.rb', line 41 def get_titulo #devuelve el tipo de comida mas su ingesta diaria s = "#{@tipo_dieta} " if (@ingesta[1] == nil) s += "(#{@ingesta[0]}%)" else s += "(#{@ingesta[0]}% - #{@ingesta[1]}%)" end s #se devuelve e imprime end |
#get_to_(pos) ⇒ Object
devuelve una linea con la descripcion completa de un plato
56 57 58 59 60 61 62 63 |
# File 'lib/pract07/Dieta.rb', line 56 def get_to_(pos) #devuelve una linea con la descripcion completa de un plato s = "- #{@descripcion[pos]}, " if (@racion[pos] != nil) s += "#{@racion[pos]}, " end s += "#{@cantidad[pos]} g" s #se devuelve e imprime end |
#to_s ⇒ Object
devuelve la salida con todos los datos
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 95 |
# File 'lib/pract07/Dieta.rb', line 65 def to_s #devuelve la salida con todos los datos s = "#{@tipo_dieta} " if (@ingesta[1] == nil) s += "(#{@ingesta[0]}%)" else s += "(#{@ingesta[0]}% - #{@ingesta[1]}%)" end s += "\n" @i = 0 while (@descripcion[@i] != nil && @cantidad[@i] != nil) do s += "- #{@descripcion[@i]}, " if (@racion[@i] != nil) s += "#{@racion[@i]}, " end s += "#{@cantidad[@i]} g" s += "\n" @i += 1 end s += "V.C.T. | %" s += "\t" s += "#{@kcal} kcal |" @j = 0 while (@percent[@j] != nil) if (@j != 0) s += " -" end s += " #{@percent[@j]}%" @j += 1 end s #se devuelve e imprime end |