Class: Dsl_menu
- Inherits:
-
Object
- Object
- Dsl_menu
- Defined in:
- lib/InforNutricional/dsl.rb
Constant Summary collapse
- @@equivalencias =
Equivalencias de las porciones en gramos
{"pieza"=>200, "taza"=>250, "cucharón"=>80, "rodaja"=>50, "vaso"=>200, "porción"=>100}
Instance Attribute Summary collapse
-
#almuerzos ⇒ Object
readonly
Returns the value of attribute almuerzos.
-
#cenas ⇒ Object
readonly
Returns the value of attribute cenas.
-
#desayunos ⇒ Object
readonly
Returns the value of attribute desayunos.
-
#ingesta(opciones = {}) ⇒ Object
readonly
Returns the value of attribute ingesta.
Instance Method Summary collapse
- #almuerzo(opciones = {}) ⇒ Object
- #cena(opciones = {}) ⇒ Object
- #convertidor(porcion) ⇒ Object
- #desayuno(opciones = {}) ⇒ Object
-
#initialize(dia, &bloque) ⇒ Dsl_menu
constructor
A new instance of Dsl_menu.
- #titulo(titulo_aux) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dia, &bloque) ⇒ Dsl_menu
Returns a new instance of Dsl_menu.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/InforNutricional/dsl.rb', line 9 def initialize (dia, &bloque) @desayunos = ["Desayuno"] @almuerzos = ["Almuerzo"] @cenas = ["Cena"] @dia = dia @v_energ_total = 0.0 instance_eval(&bloque) end |
Instance Attribute Details
#almuerzos ⇒ Object (readonly)
Returns the value of attribute almuerzos.
3 4 5 |
# File 'lib/InforNutricional/dsl.rb', line 3 def almuerzos @almuerzos end |
#cenas ⇒ Object (readonly)
Returns the value of attribute cenas.
3 4 5 |
# File 'lib/InforNutricional/dsl.rb', line 3 def cenas @cenas end |
#desayunos ⇒ Object (readonly)
Returns the value of attribute desayunos.
3 4 5 |
# File 'lib/InforNutricional/dsl.rb', line 3 def desayunos @desayunos end |
#ingesta(opciones = {}) ⇒ Object (readonly)
Returns the value of attribute ingesta.
3 4 5 |
# File 'lib/InforNutricional/dsl.rb', line 3 def ingesta @ingesta end |
Instance Method Details
#almuerzo(opciones = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/InforNutricional/dsl.rb', line 63 def almuerzo( opciones={} ) if opciones[:gramos] cantidad = opciones[:gramos] elsif opciones[:porcion] cantidad = convertidor(opciones[:porcion]) end @almuerzo_aux = Nutricion.new( opciones[:descripcion], opciones[:grasas].to_f, 0.0, 0.0, opciones[:carbohidratos].to_f , 0.0, 0.0, opciones[:fibra].to_f, opciones[:proteinas].to_f, 0.0, 0.0, opciones[:sal].to_f ) @v_energ_total += @desayuno_aux.kcal @almuerzos << @almuerzo_aux end |
#cena(opciones = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/InforNutricional/dsl.rb', line 80 def cena( opciones={} ) if opciones[:gramos] cantidad = opciones[:gramos] elsif opciones[:porcion] cantidad = convertidor(opciones[:porcion]) end @cena_aux = Nutricion.new( opciones[:descripcion], opciones[:grasas], 0, 0, opciones[:carbohidratos], 0, 0, 0, opciones[:proteinas], 0, 0, opciones[:sal] ) @v_energ_total += @desayuno_aux.kcal @cenas << @cena_aux end |
#convertidor(porcion) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/InforNutricional/dsl.rb', line 37 def convertidor(porcion) num_array = porcion.split(" ")[0] word_array = porcion.split(" ")[1] gramos = num_array.to_f * @@equivalencias[word_array.chomp ' '] gramos end |
#desayuno(opciones = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/InforNutricional/dsl.rb', line 47 def desayuno(opciones={}) if opciones[:gramos] cantidad = opciones[:gramos] elsif opciones[:porcion] cantidad = convertidor(opciones[:porcion]) end @desayuno_aux = Nutricion.new(opciones[:descripcion], opciones[:grasas].to_f, 0.0, 0.0, opciones[:carbohidratos].to_f, 0.0, 0.0, 0.0, opciones[:proteinas].to_f, 0.0, 0.0, opciones[:sal].to_f ) @v_energ_total += @desayuno_aux.kcal @desayunos << @desayuno_aux end |
#titulo(titulo_aux) ⇒ Object
22 23 24 |
# File 'lib/InforNutricional/dsl.rb', line 22 def titulo(titulo_aux) @titulo = titulo_aux end |
#to_s ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/InforNutricional/dsl.rb', line 96 def to_s output = @dia + "\t" output += "\nMENU: " + @titulo output += "\n\n\t\t\tComposición nutricional: \n" output += "=============================================================================================================\n" @desayunos.each_with_index do |desayuno, index| output += "_____________________________________________________________________________________________________________\n" output += "#{desayuno.to_s}\n" end output += "_____________________________________________________________________________________________________________\n" output += ".............................................................................................................\n" @almuerzos.each_with_index do |almuerzo, index| output += "_____________________________________________________________________________________________________________\n" output += "#{almuerzo.to_s}\n" end output += "_____________________________________________________________________________________________________________\n" output += ".............................................................................................................\n" @cenas.each_with_index do |cena, index| output += "_____________________________________________________________________________________________________________\n" output += "#{cena.to_s}\n" end output += "_____________________________________________________________________________________________________________\n" output += ".............................................................................................................\n" output += "Valor energetico total = " + (@v_energ_total).round(2).to_s output += "\n=============================================================================================================\n" output end |