Sha256: 9143961974a7f610ce18c1c8ca2cab2082badc87b5f646273bfa1a96748a8441

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

#Representa un Menu
class Menu
        
    attr_accessor :platos, :titulo_porcentaje, :porcentaje, :title, :name
    
    include Comparable
    
   # Constructor
    def initialize(name, &block)
        self.name = name
        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
    
    def titulo(text)
       title << text
    end
    
    def ingesta(options = {})
        titulo_porcentaje << "#{options[:min]}" if options[:min]
        titulo_porcentaje << "#{options[:max]}" if options[:max]
    end
    
    
    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
    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
    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
    
     def <=> (other)
            porcentajes <=> other.porcentajes
     end
    
end
    

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
MenuDieteticoComparable-0.3.0 lib/dieta/Menu.rb