Class: Dieta
Overview
Clase que representa un menu
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
-
#platos ⇒ Object
Returns the value of attribute platos.
-
#porcentaje ⇒ Object
Returns the value of attribute porcentaje.
-
#title ⇒ Object
Returns the value of attribute title.
-
#titulo_porcentaje ⇒ Object
Returns the value of attribute titulo_porcentaje.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(label, &block) ⇒ Dieta
constructor
Constructor de la clase.
-
#plato(options = {}) ⇒ Object
Obtener un plato.
- #porcentajes(options = {}) ⇒ Object
- #titulo(text) ⇒ Object
-
#titulo_porcentajes(options = {}) ⇒ Object
Obtener porcentaje.
- #to_s ⇒ Object
Constructor Details
#initialize(label, &block) ⇒ Dieta
Constructor de la clase
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/menus/dieta.rb', line 13 def initialize(label, &block) self.label = label self.title = "" self.titulo_porcentaje = [] self.platos = [] self.porcentaje = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
4 5 6 |
# File 'lib/menus/dieta.rb', line 4 def label @label end |
#platos ⇒ Object
Returns the value of attribute platos.
4 5 6 |
# File 'lib/menus/dieta.rb', line 4 def platos @platos end |
#porcentaje ⇒ Object
Returns the value of attribute porcentaje.
4 5 6 |
# File 'lib/menus/dieta.rb', line 4 def porcentaje @porcentaje end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/menus/dieta.rb', line 4 def title @title end |
#titulo_porcentaje ⇒ Object
Returns the value of attribute titulo_porcentaje.
4 5 6 |
# File 'lib/menus/dieta.rb', line 4 def titulo_porcentaje @titulo_porcentaje end |
Instance Method Details
#<=>(other) ⇒ Object
8 9 10 |
# File 'lib/menus/dieta.rb', line 8 def <=>(other) @vct <=> other.vct end |
#plato(options = {}) ⇒ Object
Obtener un plato
41 42 43 44 45 46 47 |
# File 'lib/menus/dieta.rb', line 41 def plato( = {}) plat = [] plat << "#{[:descripcion]}" if [:descripcion] plat << "#{[:porcion]}" if [:porcion] plat << "#{[:gramos]}" if [:gramos] platos << plat end |
#porcentajes(options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/menus/dieta.rb', line 49 def porcentajes( = {}) porcentaje << "#{[:vct]}" if [:vct] porcentaje << "#{[:proteinas]}" if [:proteinas] porcentaje << "#{[:hidratos]}" if [:hidratos] porcentaje << "#{[:grasas]}" if [:grasas] end |
#titulo(text) ⇒ Object
30 31 32 |
# File 'lib/menus/dieta.rb', line 30 def titulo(text) title << text end |
#titulo_porcentajes(options = {}) ⇒ Object
Obtener porcentaje
34 35 36 37 |
# File 'lib/menus/dieta.rb', line 34 def titulo_porcentajes( = {}) titulo_porcentaje << "#{[:min]}" if [:min] titulo_porcentaje << "#{[:max]}" if [:max] end |
#to_s ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/menus/dieta.rb', line 56 def to_s formato = "#{title} " output = formato output << "(" + titulo_porcentaje.map { |k| "#{k}%" }.join(" - ") + ")\n" platos.each do |plato| output << "- #{plato[0]}, #{plato[1]}, #{plato[2]}gr\n" end output << "V.C.T. | %\t #{porcentaje[0]} kcal | #{porcentaje[1]}% - #{porcentaje[2]}% - #{porcentaje[3]}%" return output end |