class MenuDE

Attributes

edades[R]
grasas[R]
grupo[R]
hidratos[R]
platos[R]
porcentaje[R]
proteinas[R]
titulo[R]
vct[R]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/menu/menude.rb, line 8
def initialize(&bloque)
    @titulo
    @porcentaje
    @platos = []
    @vct
    @proteinas
    @grasas
    @hidratos
    @grupo
    @edades
    
    if block_given?  
        if bloque.arity == 1
            yield self
        else
            instance_eval(&bloque) 
        end
    end
end

Public Instance Methods

<=>(anOther) click to toggle source
# File lib/menu/menude.rb, line 68
def <=>(anOther)
    return nil if anOther == nil
    x=[ cogefloat(vct)]
    y=[ cogefloat(anOther.vct)]
    x <=> y
end
==(anOther) click to toggle source
# File lib/menu/menude.rb, line 75
def ==(anOther)
    return nil if anOther == nil
    x=[ cogefloat(vct), cogefloat(proteinas), cogefloat(grasas), cogefloat(hidratos) ]
    y=[ cogefloat(anOther.vct), cogefloat(anOther.proteinas), cogefloat(anOther.grasas), cogefloat(anOther.hidratos) ]
    x==y
end
cogefloat(dato) click to toggle source

Métdodo auxiliar que le pasas un string por parametro y nos lo transformaen float.

# File lib/menu/menude.rb, line 59
def cogefloat(dato)
   number =dato.gsub(/[a-z]/,"")
   number =number.gsub("%",".")
   number =number.gsub(",",".")
   number =number.to_f
   return number
end
corregir_porcentaje() click to toggle source
# File lib/menu/menude.rb, line 89
def corregir_porcentaje
    t = ""
    @porcentaje.each{|x| t = t + " - " + x.to_s}
    final = t[3,t.length]
    final
end
getConjuntoPlatos() click to toggle source
# File lib/menu/menude.rb, line 128
def getConjuntoPlatos
    t = ""
    @platos.each{|x| t = t + x.to_s + "\n"}
    t
end
getDescripcion(x) click to toggle source
# File lib/menu/menude.rb, line 124
def getDescripcion (x)
    @platos[x].descripcion
end
getGrasas() click to toggle source
# File lib/menu/menude.rb, line 116
def getGrasas
    @grasas 
end
getHidrados() click to toggle source
# File lib/menu/menude.rb, line 120
def getHidrados
    @hidratos 
end
getIngesta() click to toggle source
# File lib/menu/menude.rb, line 104
def getIngesta
    @porcentaje 
end
getPlato(index) click to toggle source
# File lib/menu/menude.rb, line 96
def getPlato(index)
    @platos[index].to_s
end
getProteinas() click to toggle source
# File lib/menu/menude.rb, line 112
def getProteinas
    @proteinas 
end
getTitulo() click to toggle source
# File lib/menu/menude.rb, line 100
def getTitulo
    @titulo
end
getVct() click to toggle source
# File lib/menu/menude.rb, line 108
def getVct
    @vct 
end
ingesta(options = {}) click to toggle source
# File lib/menu/menude.rb, line 42
def ingesta (options = {})
    porcentaje = []
    porcentaje << "#{options[:min]}" if options[:min]
    porcentaje << "#{options[:max]}" if options[:max]
    @porcentaje = porcentaje
end
plato(options = {}) click to toggle source
# File lib/menu/menude.rb, line 28
def plato (options = {})
    plato = []
    plato << "#{options[:descripcion]}" if options[:descripcion]
    plato << "#{options[:porcion]}" if options[:porcion]
    plato << "#{options[:gramos]}" if options[:gramos]
    @platos.push(Plato.new(plato))
end
porcentajes(options = {}) click to toggle source
# File lib/menu/menude.rb, line 49
def porcentajes (options = {})
    @vct = "#{options[:vct]}" if options[:vct]
    @proteinas = "#{options[:proteinas]}" if options[:proteinas]
    @grasas = "#{options[:grasas]}" if options[:grasas]
    @hidratos = "#{options[:hidratos]}" if options[:hidratos]
end
to_s() click to toggle source
# File lib/menu/menude.rb, line 83
def to_s
    porcentaje = corregir_porcentaje
    @titulo + " (#{porcentaje}%)\n" + getConjuntoPlatos + "V.C.T. | % " + getVct + " kcal | " + getProteinas + "% - " + getGrasas + "% - " + 
    getHidrados + "%\n Grupo de alimentos: " + grupo.to_s + "\n Grupo de edad: " + edades.to_s + "\n"
end