class Menu

Attributes

almuerzo[R]
cena[R]
desayuno[R]
dia[R]
ingesta[R]
titulo[R]

Public Class Methods

new(nombre) { |self| ... } click to toggle source
# 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

Public Instance Methods

to_s() click to toggle source
# 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() click to toggle source
# 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