class MenuDSL

Attributes

ingest[RW]
name[RW]
plato[RW]
porcent[RW]
titul[RW]

Public Class Methods

new(name) { |self| ... } click to toggle source
# File lib/menu/menudsl.rb, line 5
def initialize(name,&block)
    self.name = name
    self.titul = []
    self.ingest = []
    self.plato = []
    self.porcent = []
    
    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval &block
        end
    end
end

Public Instance Methods

ingesta(text, options = {}) click to toggle source
# File lib/menu/menudsl.rb, line 63
def ingesta(text, options = {})
    ing = text
    ing << "#{options[:min]} -" if options[:min]
    ing << " #{options[:max]} %" if options[:max]
    
    ingest << ing
end
platos(text, options = {}) click to toggle source
# File lib/menu/menudsl.rb, line 71
def platos(text, options = {})
    plat = text
    plat << "#{options[:description]}, " if options[:description]
    plat << "#{options[:porcion]}, " if options[:porcion]
    plat << "#{options[:gramos]}" if options[:gramos]
    
    plato << plat
end
porcentajes(text,options = {}) click to toggle source
# File lib/menu/menudsl.rb, line 53
def porcentajes(text,options = {})
    porcentaje = text
    porcentaje << "#{options[:vct]} kcal | " if options[:vct]
    porcentaje << "#{options[:proteinas]}% - " if options[:proteinas]
    porcentaje << "#{options[:grasas]}% - " if options[:grasas]
    porcentaje << "#{options[:hidratos]}%" if options[:hidratos]
    
    porcent << porcentaje
end
titulo(text, options = {}) click to toggle source
# File lib/menu/menudsl.rb, line 47
def titulo(text, options = {})
    title = text
    
    titul << title
end
to_s() click to toggle source
# File lib/menu/menudsl.rb, line 21
def to_s

    output = "#{name}\n"
    titul.each do |title|
        output << "#{title}"
        output << "\n#{'=' * title.size}\n"
    end
    
    ingest.each do |ing|
        output << "#{ing}"
    end

    plato.each_with_index do |plat, index|
        output << "\n#{index + 1})#{plat}"
    end
    
    output << "\nV.C.T | % "
    
    porcent.each do |porcentaje|
        output << "#{porcentaje}"
    end
    output << "\n"
    
    output
end