class Alimento::Plato
Attributes
grams[RW]
ingredients[RW]
name[RW]
Public Class Methods
new(name) { |self| ... }
click to toggle source
# File lib/alimento/plato.rb, line 37 def initialize(name, &block) @name = name @ingredients = [] @grams = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end
Public Instance Methods
aceite(name, options = {})
click to toggle source
# File lib/alimento/plato.rb, line 100 def aceite(name, options = {}) alimento = $alimentos.find{ |x| x.nombre == name } cantidad = amount(options) @ingredients << alimento @grams << cantidad end
amount(options = {})
click to toggle source
# File lib/alimento/plato.rb, line 107 def amount(options = {}) cantidad = 1 cantidad = options[:gramos] if options[:gramos] cantidad = options[:porcion].chars.reject{ |x| x =~ /[^\d.\/]/ }.join("").to_r*15 if /cucharada/ =~ options[:porcion] cantidad = options[:porcion].chars.reject{ |x| x =~ /[^\d.\/]/ }.join("").to_r*250 if /cucharón/ =~ options[:porcion] cantidad = options[:porcion].chars.reject{ |x| x =~ /[^\d.\/]/ }.join("").to_r*225 if /taza/ =~ options[:porcion] cantidad = options[:porcion].chars.reject{ |x| x =~ /[^\d.\/]/ }.join("").to_r*220 if /pieza/ =~ options[:porcion] cantidad = options[:porcion].chars.reject{ |x| x =~ /[^\d.\/]/ }.join("").to_r*110 if /pieza/ =~ options[:porcion] && /pequeña/ =~ options[:porcion] cantidad end
cereal(name, options = {})
click to toggle source
# File lib/alimento/plato.rb, line 86 def cereal(name, options = {}) alimento = $alimentos.find{ |x| x.nombre == name } cantidad = amount(options) @ingredients << alimento @grams << cantidad end
fruta(name, options = {})
click to toggle source
# File lib/alimento/plato.rb, line 79 def fruta(name, options = {}) alimento = $alimentos.find{ |x| x.nombre == name } cantidad = amount(options) @ingredients << alimento @grams << cantidad end
proteina(name, options = {})
click to toggle source
# File lib/alimento/plato.rb, line 93 def proteina(name, options = {}) alimento = $alimentos.find{ |x| x.nombre == name } cantidad = amount(options) @ingredients << alimento @grams << cantidad end
to_s()
click to toggle source
# File lib/alimento/plato.rb, line 51 def to_s output = @name output << "\n#{'=' * @name.size}\n" output << "Composición nutricional:\n" output << "#{' ' * 16}glúcidos proteínas lípidos\tvalor energético\n" valor = 0.0 @ingredients.each_with_index do |ing, i| output << "#{ing}" output << "#{' ' * (16 - ing.nombre.size)}" output << "#{(ing.glucidos * @grams[i]).round(2)}\t " output << "#{(ing.proteinas * @grams[i]).round(2)}\t " output << "#{(ing.lipidos * @grams[i]).round(2)} \t" output << "#{(ing.kcal * @grams[i]).round(2)}\n" valor += ing.kcal * @grams[i] end output << "\nvalor energético total\t\t\t\t#{valor.round(2)}" output end
vegetal(name, options = {})
click to toggle source
# File lib/alimento/plato.rb, line 72 def vegetal(name, options = {}) alimento = $alimentos.find{ |x| x.nombre == name } cantidad = amount(options) @ingredients << alimento @grams << cantidad end