Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/alu0100987522/menu.rb
Instance Attribute Summary collapse
-
#almuerzo(alimento, composicion = {}) ⇒ Object
readonly
Returns the value of attribute almuerzo.
-
#cena(alimento, composicion = {}) ⇒ Object
readonly
Returns the value of attribute cena.
-
#desayuno(alimento, composicion = {}) ⇒ Object
readonly
Returns the value of attribute desayuno.
-
#dia ⇒ Object
readonly
Returns the value of attribute dia.
-
#ingesta(intervalo = {}) ⇒ Object
readonly
Returns the value of attribute ingesta.
-
#titulo(text) ⇒ Object
readonly
Returns the value of attribute titulo.
Instance Method Summary collapse
-
#initialize(nombre, &block) ⇒ Menu
constructor
A new instance of Menu.
- #to_s ⇒ Object
- #total_ve ⇒ 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 |
# File 'lib/alu0100987522/menu.rb', line 5 def initialize(nombre, &block) @nombre = nombre @ingesta = [] @desayuno = [] @almuerzo = [] @cena = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#almuerzo(alimento, composicion = {}) ⇒ Object (readonly)
Returns the value of attribute almuerzo.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def almuerzo @almuerzo end |
#cena(alimento, composicion = {}) ⇒ Object (readonly)
Returns the value of attribute cena.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def cena @cena end |
#desayuno(alimento, composicion = {}) ⇒ Object (readonly)
Returns the value of attribute desayuno.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def desayuno @desayuno end |
#dia ⇒ Object (readonly)
Returns the value of attribute dia.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def dia @dia end |
#ingesta(intervalo = {}) ⇒ Object (readonly)
Returns the value of attribute ingesta.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def ingesta @ingesta end |
#titulo(text) ⇒ Object (readonly)
Returns the value of attribute titulo.
3 4 5 |
# File 'lib/alu0100987522/menu.rb', line 3 def titulo @titulo end |
Instance Method Details
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/alu0100987522/menu.rb', line 21 def to_s output = @nombre output << "\t\t \"#{@titulo}\"" output << "\n#{'=' * 50 }\n" output << "\nTiempo estimado de ingesta: #{@ingesta.join(' -')} minutos.\n" output << "- Desayuno:\n" @desayuno.each_with_index do |alimento, index| output << "#{index+1}) #{alimento}\n" end output << "\n- Almuerzo:\n" @almuerzo.each_with_index do |alimento, index| output << "#{index+1}) #{alimento}\n" end output << "\n- Cena:\n" @cena.each_with_index do |alimento, index| output << "#{index+1}) #{alimento}\n" end output << "\n Valor energético total del menú: #{total_ve}\n" output end |
#total_ve ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/alu0100987522/menu.rb', line 93 def total_ve all = 0.0 all += @desayuno.map { |ali| ali.val_energetico }.reduce(:+) all += @almuerzo.map { |ali| ali.val_energetico }.reduce(:+) all += @cena.map { |ali| ali.val_energetico }.reduce(:+) return all.round(3) end |