Class: DslDieta
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Int
1 if self>other, 0 if self == other, -1 if self<other.
- #ingesta(args = {}) ⇒ Object
-
#initialize(titulo, &block) ⇒ DslDieta
constructor
A new instance of DslDieta.
- #plato(args = {}) ⇒ Object
- #porcentajes(args = {}) ⇒ Object
-
#to_s ⇒ String
String con el contenido de la lista.
Constructor Details
#initialize(titulo, &block) ⇒ DslDieta
Returns a new instance of DslDieta
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/prct06/dslDieta.rb', line 13 def initialize(titulo,&block) self.titulo=titulo self.platos =[] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def grasas @grasas end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def hidratos @hidratos end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def max @max end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def min @min end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def platos @platos end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def proteinas @proteinas end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def titulo @titulo end |
#M ⇒ Object
10 11 12 |
# File 'lib/prct06/dslDieta.rb', line 10 def vct @vct end |
Instance Method Details
#<=>(other) ⇒ Int
Note:
Función que permite comparar dos dietas en función de sus valor calorífico.
Returns 1 if self>other, 0 if self == other, -1 if self<other
39 40 41 |
# File 'lib/prct06/dslDieta.rb', line 39 def <=>(other) self.vct<=>other.vct end |
#ingesta(args = {}) ⇒ Object
Note:
Función que permite asignar valor a los atributos max y min.
44 45 46 47 |
# File 'lib/prct06/dslDieta.rb', line 44 def ingesta(args = {}) self.max="#{args[:max]}" if args[:max] self.min="#{args[:min]}" if args[:min] end |
#plato(args = {}) ⇒ Object
Note:
Función que permite añadir un nuevo plato a la dieta.
50 51 52 53 54 55 |
# File 'lib/prct06/dslDieta.rb', line 50 def plato(args = {}) input = " -#{args[:descripcion]}" if args[:descripcion] input += ", #{args[:porcion]}" if args[:porcion] input += ", #{args[:gramos]} gramos" if args[:gramos] self.platos << "#{input}" end |
#porcentajes(args = {}) ⇒ Object
Note:
Función que permite asignar valor a los parámetros: vct, proteinas, grasas y hidratos.
58 59 60 61 62 63 |
# File 'lib/prct06/dslDieta.rb', line 58 def porcentajes(args = {}) self.vct="#{args[:vct]}" if args[:vct] self.proteinas="#{args[:proteinas]}" if args[:proteinas] self.grasas="#{args[:grasas]}" if args[:grasas] self.hidratos="#{args[:hidratos]}" if args[:hidratos] end |
#to_s ⇒ String
Returns String con el contenido de la lista
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/prct06/dslDieta.rb', line 26 def to_s output = "#{titulo} (#{min}-#{max}%):\n" i=0 begin output+="#{platos[i]}\n" i+=1 end while (i<platos.length) output += "V.C.T. | % #{vct} kcal | #{proteinas}% - #{grasas}% - #{hidratos}%\n" "#{output}" end |