Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/InformacionNutricional/menu.rb
Instance Attribute Summary collapse
-
#almuerzo(options = {}) ⇒ Object
Returns the value of attribute almuerzo.
-
#cena(options = {}) ⇒ Object
Returns the value of attribute cena.
-
#desayuno(options = {}) ⇒ Object
Returns the value of attribute desayuno.
-
#ingesta(options = {}) ⇒ Object
Returns the value of attribute ingesta.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
-
#titulo(titulo) ⇒ Object
Returns the value of attribute titulo.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #calculate_calories(grasas, carbs, proteina, sal) ⇒ Object
-
#initialize(nombre, &block) ⇒ Menu
constructor
A new instance of Menu.
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, &block) ⇒ Menu
Returns a new instance of Menu.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/InformacionNutricional/menu.rb', line 5 def initialize(nombre, &block) @nombre = nombre @titulo = "" @ingesta = [] @desayuno = [] @almuerzo = [] @cena = [] @total = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#almuerzo(options = {}) ⇒ Object
Returns the value of attribute almuerzo.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def almuerzo @almuerzo end |
#cena(options = {}) ⇒ Object
Returns the value of attribute cena.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def cena @cena end |
#desayuno(options = {}) ⇒ Object
Returns the value of attribute desayuno.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def desayuno @desayuno end |
#ingesta(options = {}) ⇒ Object
Returns the value of attribute ingesta.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def ingesta @ingesta end |
#nombre ⇒ Object
Returns the value of attribute nombre.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def nombre @nombre end |
#titulo(titulo) ⇒ Object
Returns the value of attribute titulo.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def titulo @titulo end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/InformacionNutricional/menu.rb', line 3 def total @total end |
Instance Method Details
#calculate_calories(grasas, carbs, proteina, sal) ⇒ Object
23 24 25 26 27 |
# File 'lib/InformacionNutricional/menu.rb', line 23 def calculate_calories(grasas, carbs, proteina, sal) kcal = ((grasas.to_f * 9) + (carbs.to_f * 4) + (proteina.to_f * 4) + (sal.to_f * 6)).round(2) @total += kcal kcal end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/InformacionNutricional/menu.rb', line 29 def to_s output = @nombre output << "#{' ' * (30 - @nombre.size)} Composición nutricional" output << "\n#{'=' * 120}" output << "\n#{' ' * 30}" output << "grasas".ljust(15) output << "carbs".ljust(15) output << "proteínas".ljust(15) output << "fibra".ljust(15) output << "sal".ljust(15) output << "Kcal".ljust(15) output << "\nDesayuno" @desayuno.each do |comida| output << "\n" comida.each_with_index do |opcion, index| if index == 0 name = "#{opcion}" output << "#{opcion} #{' ' * (30-name.size)}" elsif index != 1 && index != 2 output << "#{opcion}".ljust(15) end end end output << "\n#{'-' * 120}" @almuerzo.each do |comida| output << "\n" comida.each_with_index do |opcion, index| if index == 0 name = "#{opcion}" output << "#{opcion} #{' ' * (30-name.size)}" elsif index != 1 && index != 2 output << "#{opcion}".ljust(15) end end end output << "\n#{'-' * 120}" @cena.each do |comida| output << "\n" comida.each_with_index do |opcion, index| if index == 0 name = "#{opcion}" output << "#{opcion} #{' ' * (30-name.size)}" elsif index != 1 && index != 2 output << "#{opcion}".ljust(15) end end end output << "\n#{'-' * 120}\n" output << "Kcal totales".ljust(15) output << (@total.round(2)).to_s output end |