module Dieta class Dieta attr_reader :titulo, :porcentaje, :platos, :datos include Comparable def initialize(&block) @titulo = '' @porcentaje = [] @platos = [] @datos = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end def <=>(other) datos <=> other.datos end def titulo_(name) @titulo = name end 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 def ingesta_(opciones = {}) ingesta = '' ingesta << (opciones[:porcentaje]).to_s if opciones[:porcentaje] @porcentaje = ingesta.to_i end 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 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 def get_titulo @titulo end def get_porcentaje_diario @porcentaje end def get_plato(i) @platos[i] end def get_platos @platos end def get_vct @datos[0] end def get_proteinas @datos[1] end def get_grasas @datos[2] end def get_hidratos @datos[3] end def get_desc_plato(i) @platos[i][0] + ': ' + " #{@platos[i][1]}, " + " #{@platos[i][2]} gramos" end end class Dieta_alimentos < Dieta attr_reader :alimentos def initialize(alimentos, dieta) super(dieta.titulo, dieta.porcentaje, dieta.platos, dieta.datos) @alimentos = alimentos end end class Dieta_edad < Dieta attr_reader :edad def initialize(edad, dieta) super(dieta.titulo, dieta.porcentaje, dieta.platos, dieta.datos) @edad = edad end end end