class Dieta
Clase que representa un menu
Attributes
label[RW]
platos[RW]
porcentaje[RW]
title[RW]
titulo_porcentaje[RW]
Public Class Methods
new(label) { |self| ... }
click to toggle source
Constructor de la clase
# File lib/menus/dieta.rb, line 13 def initialize(label, &block) self.label = label self.title = "" self.titulo_porcentaje = [] self.platos = [] self.porcentaje = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/menus/dieta.rb, line 8 def <=>(other) @vct <=> other.vct end
plato(options = {})
click to toggle source
Obtener un plato
# File lib/menus/dieta.rb, line 41 def plato(options = {}) plat = [] plat << "#{options[:descripcion]}" if options[:descripcion] plat << "#{options[:porcion]}" if options[:porcion] plat << "#{options[:gramos]}" if options[:gramos] platos << plat end
porcentajes(options = {})
click to toggle source
# File lib/menus/dieta.rb, line 49 def porcentajes(options = {}) porcentaje << "#{options[:vct]}" if options[:vct] porcentaje << "#{options[:proteinas]}" if options[:proteinas] porcentaje << "#{options[:hidratos]}" if options[:hidratos] porcentaje << "#{options[:grasas]}" if options[:grasas] end
titulo(text)
click to toggle source
# File lib/menus/dieta.rb, line 30 def titulo(text) title << text end
titulo_porcentajes(options = {})
click to toggle source
Obtener porcentaje
# File lib/menus/dieta.rb, line 34 def titulo_porcentajes(options = {}) titulo_porcentaje << "#{options[:min]}" if options[:min] titulo_porcentaje << "#{options[:max]}" if options[:max] end
to_s()
click to toggle source
# File lib/menus/dieta.rb, line 56 def to_s formato = "#{title} " output = formato output << "(" + titulo_porcentaje.map { |k| "#{k}%" }.join(" - ") + ")\n" platos.each do |plato| output << "- #{plato[0]}, #{plato[1]}, #{plato[2]}gr\n" end output << "V.C.T. | %\t #{porcentaje[0]} kcal | #{porcentaje[1]}% - #{porcentaje[2]}% - #{porcentaje[3]}%" return output end