Class: Dieta
Overview
clase principal de la jerarquía
Direct Known Subclasses
Instance Attribute Summary collapse
-
#grasas ⇒ Object
attr.
-
#hidratos ⇒ Object
attr.
-
#nombre ⇒ Object
attr.
-
#nplatos ⇒ Object
attr.
-
#platos ⇒ Object
attr.
-
#porcentaje_ingesta ⇒ Object
attr.
-
#proteinas ⇒ Object
attr.
-
#titulo ⇒ Object
attr.
-
#vct ⇒ Object
attr.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
invalidación del <=> para hacer los objetos comparables.
-
#get_plato(n) ⇒ Object
acceso a un plato en concreto.
-
#ingesta(porcentaje = {}) ⇒ Object
función para definir el porcentaje de ingesta.
-
#initialize(nombre, &block) ⇒ Dieta
constructor
constructor.
-
#plato(options = {}) ⇒ Object
función para definir platos nuevos.
-
#porcentajes(options = {}) ⇒ Object
función para definir los porcentajes de grasa, proteínas, hidratos y el valor calórico total.
-
#tipo(ntitulo) ⇒ Object
función para definir el título del menú: almuerzo, cena, etc.
-
#to_s ⇒ Object
formateo a string.
Constructor Details
#initialize(nombre, &block) ⇒ Dieta
constructor
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/prct06/Dieta.rb', line 13 def initialize (nombre, &block) self.nombre = nombre self.titulo self.porcentaje_ingesta self.nplatos self.platos = [] self.vct self.proteinas self.grasas self.hidratos if block_given? if block.arity == 1 yield self else instance_eval &block end end end |
Instance Attribute Details
#grasas ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def grasas @grasas end |
#hidratos ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def hidratos @hidratos end |
#nombre ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def nombre @nombre end |
#nplatos ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def nplatos @nplatos end |
#platos ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def platos @platos end |
#porcentaje_ingesta ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def porcentaje_ingesta @porcentaje_ingesta end |
#proteinas ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def proteinas @proteinas end |
#titulo ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def titulo @titulo end |
#vct ⇒ Object
attr
10 11 12 |
# File 'lib/prct06/Dieta.rb', line 10 def vct @vct end |
Instance Method Details
#<=>(other) ⇒ Object
invalidación del <=> para hacer los objetos comparables
79 80 81 82 |
# File 'lib/prct06/Dieta.rb', line 79 def <=> (other) return nil unless other.is_a?Dieta self.vct <=> other.vct end |
#get_plato(n) ⇒ Object
acceso a un plato en concreto
71 72 73 74 75 76 |
# File 'lib/prct06/Dieta.rb', line 71 def get_plato (n) if n < 1 then return "" end return platos[n-1] end |
#ingesta(porcentaje = {}) ⇒ Object
función para definir el porcentaje de ingesta. Podría darse una estimación entre dos
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/prct06/Dieta.rb', line 41 def ingesta(porcentaje = {}) standard = porcentaje[:fijo] if porcentaje[:fijo] low = porcentaje[:min] if porcentaje[:min] up = porcentaje[:max] if porcentaje[:max] if porcentaje[:fijo] then self.porcentaje_ingesta = "#{standard}%" else self.porcentaje_ingesta = "#{low}% - #{up}%" end end |
#plato(options = {}) ⇒ Object
función para definir platos nuevos
62 63 64 65 66 67 68 |
# File 'lib/prct06/Dieta.rb', line 62 def plato( = {}) nuevo = [] nuevo << "#{[:descripcion]}" if [:descripcion] nuevo << "#{[:porcion]}" if [:porcion] nuevo << [:gramos] if [:gramos] platos << nuevo end |
#porcentajes(options = {}) ⇒ Object
función para definir los porcentajes de grasa, proteínas, hidratos y el valor calórico total
54 55 56 57 58 59 |
# File 'lib/prct06/Dieta.rb', line 54 def porcentajes( = {}) self.vct = [:vct] if [:vct] self.proteinas = [:proteinas] if [:proteinas] self.grasas = [:grasas] if [:grasas] self.hidratos = [:hidratos] if [:hidratos] end |
#tipo(ntitulo) ⇒ Object
función para definir el título del menú: almuerzo, cena, etc.
36 37 38 |
# File 'lib/prct06/Dieta.rb', line 36 def tipo(ntitulo) self.titulo = ntitulo end |
#to_s ⇒ Object
formateo a string
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/prct06/Dieta.rb', line 85 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}\n\n" end |