class Dieta::Dieta

Attributes

datos[R]
platos[R]
porcentaje[R]
titulo[R]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/dieta/dieta.rb, line 6
def initialize(&block)
    @titulo = ''
    @porcentaje = []
    @platos = []
    @datos = []

    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/dieta/dieta.rb, line 21
def <=>(other)
    datos <=> other.datos
end
get_desc_plato(i) click to toggle source
# File lib/dieta/dieta.rb, line 102
def get_desc_plato(i)
    @platos[i][0] + ': ' + " #{@platos[i][1]}, " + " #{@platos[i][2]} gramos"
end
get_grasas() click to toggle source
# File lib/dieta/dieta.rb, line 94
def get_grasas
    @datos[2]
end
get_hidratos() click to toggle source
# File lib/dieta/dieta.rb, line 98
def get_hidratos
    @datos[3]
end
get_plato(i) click to toggle source
# File lib/dieta/dieta.rb, line 78
def get_plato(i)
    @platos[i]
end
get_platos() click to toggle source
# File lib/dieta/dieta.rb, line 82
def get_platos
    @platos
end
get_porcentaje_diario() click to toggle source
# File lib/dieta/dieta.rb, line 74
def get_porcentaje_diario
    @porcentaje
end
get_proteinas() click to toggle source
# File lib/dieta/dieta.rb, line 90
def get_proteinas
    @datos[1]
end
get_titulo() click to toggle source
# File lib/dieta/dieta.rb, line 70
def get_titulo
    @titulo
end
get_vct() click to toggle source
# File lib/dieta/dieta.rb, line 86
def get_vct
    @datos[0]
end
ingesta_(opciones = {}) click to toggle source
# File lib/dieta/dieta.rb, line 39
def ingesta_(opciones = {})
    ingesta = ''
    ingesta << (opciones[:porcentaje]).to_s if opciones[:porcentaje]
    @porcentaje = ingesta.to_i
end
plato_(opciones = {}) click to toggle source
# File lib/dieta/dieta.rb, line 29
def plato_(opciones = {})
    descripcion = ''
    porcion = ''
    gramos = (opciones[:gramos]).to_s if opciones[:gramos]
    descripcion = opciones[:descripcion] if opciones [:descripcion]
    porcion = opciones[:porcion] if opciones[:porcion]

    @platos.push([descripcion, porcion, gramos.to_i])
end
porcentajes_(opciones = {}) click to toggle source
# File lib/dieta/dieta.rb, line 45
def porcentajes_(opciones = {})
    proteinas = ''
    grasas = ''
    hidratos = ''
    vct = opciones[:vct] if opciones[:vct]
    proteinas = opciones[:proteinas] if opciones[:proteinas]
    hidratos = opciones[:hidratos] if opciones[:hidratos]
    grasas = opciones[:grasas] if opciones[:grasas]
    @datos.push(vct)
    @datos.push(proteinas)
    @datos.push(grasas)
    @datos.push(hidratos)
end
titulo_(name) click to toggle source
# File lib/dieta/dieta.rb, line 25
def titulo_(name)
    @titulo = name
   end
to_s() click to toggle source
# File lib/dieta/dieta.rb, line 59
def to_s
    output = @titulo + ' | ' + @porcentaje.to_s + "%\n"

    for i in 0..@platos.size - 1
        output += '- ' + @platos[i][0] + ': ' + " #{@platos[i][1]}, " + " #{@platos[i][2]} gramos \n"
    end

    output += 'V.C.T | %    ' + "#{@datos[0]} " + 'kcal | ' + "#{@datos[1]}% - #{@datos[2]}% - #{@datos[3]}%"
    output
end