class Plato
Constants
- TABLA_ALIMENTOS
- TABLA_PORCIONES
Attributes
frutas[RW]
granos[RW]
nombre[RW]
proteinas[RW]
vegetales[RW]
vet[RW]
Public Class Methods
new(name) { |self| ... }
click to toggle source
# File lib/alimento/plato.rb, line 14 def initialize(name, &block) @nombre = name @vegetales = [] @frutas = [] @granos = [] @proteinas = [] @vet = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end
Public Instance Methods
fruta(nombre,options={})
click to toggle source
# File lib/alimento/plato.rb, line 59 def fruta(nombre,options={}) alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre} fruta = alimento.nombre fruta = alimento.nombre fruta << ": #{alimento.glucidos}" fruta << "|#{alimento.lipidos}" fruta << "|#{alimento.proteinas}" if options[:gramos] fruta << "|#{(alimento.ve*options[:gramos]).round(3)}" @vet =+ alimento.ve*options[:gramos] else fruta << "|#{alimento.ve}" @vet =+ alimento.ve end @frutas << fruta end
grano(nombre,options={})
click to toggle source
# File lib/alimento/plato.rb, line 75 def grano(nombre,options={}) alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre} grano = alimento.nombre grano << ": #{alimento.glucidos}" grano << "|#{alimento.lipidos}" grano << "|#{alimento.proteinas}" if options[:porcion] equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia grano << "|#{(alimento.ve*equivalencia).round(3)}" @vet =+ alimento.ve*equivalencia else grano << "|#{alimento.ve}" @vet =+ alimento.ve end @granos << grano end
proteina(nombre,options={})
click to toggle source
# File lib/alimento/plato.rb, line 91 def proteina(nombre,options={}) alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre} proteina = alimento.nombre proteina << ": #{alimento.glucidos}" proteina << "|#{alimento.lipidos}" proteina << "|#{alimento.proteinas}" if options[:porcion] equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia proteina << "|#{(alimento.ve*equivalencia).round(3)}" @vet =+ alimento.ve*equivalencia else proteina << "|#{alimento.ve}" @vet =+ alimento.ve end @proteinas << proteina end
to_s()
click to toggle source
# File lib/alimento/plato.rb, line 31 def to_s output = @nombre output << "\n#{'=' * @nombre.size}\n" output << "Composición nutricional: Glúcidos|Lípídos|Proteínas|Valor Energético\n" output << "#{@vegetales.join("\n")}\n" output << "#{@frutas.join("\n")}\n" output << "#{@granos.join("\n")}\n" output << "#{@proteinas.join("\n")}\n" output << "Valor energético total: #{@vet}\n" output end
vegetal(nombre,options={})
click to toggle source
# File lib/alimento/plato.rb, line 42 def vegetal(nombre,options={}) alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre} vegetal = alimento.nombre vegetal << ": #{alimento.glucidos}" vegetal << "|#{alimento.lipidos}" vegetal << "|#{alimento.proteinas}" if options[:porcion] equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia vegetal << "|#{(alimento.ve*equivalencia).round(3)}" @vet =+ alimento.ve*equivalencia else vegetal << "|#{alimento.ve}" @vet =+ alimento.ve end @vegetales << vegetal end