Class: PlatoDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/p6/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ PlatoDSL

Returns a new instance of PlatoDSL.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/p6/menu.rb', line 8

def initialize(&block)
    @nombre
    @ingredientes = []
    @peso = []
    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval(&block)
        end
    end
end

Instance Attribute Details

#ingredientesObject

Returns the value of attribute ingredientes.



6
7
8
# File 'lib/p6/menu.rb', line 6

def ingredientes
  @ingredientes
end

#nombre(name) ⇒ Object

Returns the value of attribute nombre.



6
7
8
# File 'lib/p6/menu.rb', line 6

def nombre
  @nombre
end

#pesoObject

Returns the value of attribute peso.



6
7
8
# File 'lib/p6/menu.rb', line 6

def peso
  @peso
end

Instance Method Details

#alimento(options = {}) ⇒ Object



31
32
33
34
# File 'lib/p6/menu.rb', line 31

def alimento(options = {})
    @ingredientes << options[:nombre] if options[:nombre]
    @pesos << options[:peso] if options[:peso]
end

#to_sObject



21
22
23
24
25
26
27
28
29
# File 'lib/p6/menu.rb', line 21

def to_s
    output = @nombre
    output << "\nIngredients:\n\n"
    @ingredientes.zip(@peso).each do |alimento, peso1|
        output << "\n " << alimento
        output << "\n Peso: " << peso1.to_s
    end
    output
end