class PlatoHarvard

Constants

VERSION

Version de la clase PlatoHarvard

Attributes

ingredients[R]
measures[R]
name[R]

Public Class Methods

new(name) { |self| ... } click to toggle source
# File lib/alimento/PlatoHarvard.rb, line 37
def initialize(name, &block)
    @name = name
    @ingredients = []
    @measures = []
    
    if block_given?
        if block.arity == 1 then
            yield self
        else
            instance_eval(&block)
        end
    end
end

Public Instance Methods

aceite(name, amounts = {})
Alias for: ingredient
cereales(name, amounts = {})
Alias for: ingredient
fruta(name, amounts = {})
Alias for: ingredient
ingredient(name, amounts = {}) click to toggle source
# File lib/alimento/PlatoHarvard.rb, line 51
def ingredient(name, amounts = {})
    if(@@alimentos[name]) then
        @ingredients << @@alimentos[name]
        multiplier = 0
        if(amounts[:porciones]) then
            cantidad = amounts[:porciones].scan(/\d+[,.]?\d*/).first
            
            @@medidas.each_index do |i|
                if amounts[:porciones].scan(@@medidas[i][0]).first != nil then
                    multiplier = @@medidas[i][1]
                end
            end
            @measures << (multiplier * cantidad.to_f)
        elsif(amounts[:gramos]) then
            cantidad = amounts[:gramos]
            @measures << cantidad
        end
    end
end
Also aliased as: fruta, vegetal, cereales, proteina, aceite
proteina(name, amounts = {})
Alias for: ingredient
to_s() click to toggle source
# File lib/alimento/PlatoHarvard.rb, line 77
def to_s
    texto = String.new(@name)
    texto << "\n#{'=' * @name.size}\n"
    texto << "Composicion nutricional:\n"
    texto << "#{" " * 51} %-10s %-10s %-10s%-10s\n" % ["proteínas", "glúcidos",  "lípidos", "kcal"]
    total = 0
    @ingredients.each_with_index do |i , p|
        texto << i.to_s
        total += i.kcal * @measures[p]
        texto << "%-6.2f" % [i.kcal * @measures[p] ]
        texto << "\n"
    end
    texto << "#{'=' * @name.size}\n"
    texto << "Valor energético total#{(" " * 62)}#{total}"
    return texto
end
vegetal(name, amounts = {})
Alias for: ingredient