Class: DSLMenu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ DSLMenu

Returns a new instance of DSLMenu.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/DSLMenu.rb', line 5

def initialize(nombre, &block)
    @nombre = nombre
    @platos = []
    @menu = []

    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval(&block)
        end
    end
end

Instance Attribute Details

Returns the value of attribute menu.



3
4
5
# File 'lib/DSLMenu.rb', line 3

def menu
  @menu
end

#nombreObject

Returns the value of attribute nombre.



3
4
5
# File 'lib/DSLMenu.rb', line 3

def nombre
  @nombre
end

#platosObject

Returns the value of attribute platos.



3
4
5
# File 'lib/DSLMenu.rb', line 3

def platos
  @platos
end

Instance Method Details

#plato(nombre, opciones = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/DSLMenu.rb', line 34

def plato(nombre, opciones = {})
    plato = nombre
    plato << "\n| contiene: #{opciones[:descripcion]} " if opciones[:descripcion]
    plato << "  | valor nutricional: #{opciones[:nutricional]}" if opciones[:nutricional]
    plato << "  | impacto ambiental: #{opciones[:ambiental]}" if opciones[:ambiental]
    plato << "\n\n #{opciones[:precio]} €\n" if opciones[:precio]
    @platos << plato
end

#to_sObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/DSLMenu.rb', line 19

def to_s
    output = "\n\n\n" + @nombre.upcase
    output << "\n#{'='*@nombre.size}\n\n "
    @menu.each do |menu|
        output << "#{menu}"
    end
    output << "\n\n"
    @platos.each_with_index do |plato, i|
        output << "[#{i + 1}] #{plato}\n"
    end

    output << "\n\n\n"
    output
end