Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Menu

Returns a new instance of Menu.



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

def initialize(name, &block)
    @name = name
    @desc_menus = []
    @menu = []
    @precios = []
    @total=0

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

Instance Attribute Details

#desc_menusObject (readonly)

Returns the value of attribute desc_menus.



2
3
4
# File 'lib/practica/menu.rb', line 2

def desc_menus
  @desc_menus
end

Returns the value of attribute menu.



2
3
4
# File 'lib/practica/menu.rb', line 2

def menu
  @menu
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/practica/menu.rb', line 2

def name
  @name
end

#preciosObject (readonly)

Returns the value of attribute precios.



2
3
4
# File 'lib/practica/menu.rb', line 2

def precios
  @precios
end

#totalObject (readonly)

Returns the value of attribute total.



2
3
4
# File 'lib/practica/menu.rb', line 2

def total
  @total
end

Instance Method Details

#componente(bloque = {}) ⇒ Object



19
20
21
22
23
# File 'lib/practica/menu.rb', line 19

def componente(bloque = {})
    @desc_menus << bloque[:descripcion]
    @menu << bloque[:platos]
    @precios << bloque[:precio]
end

#precio(coste) ⇒ Object



24
25
26
27
# File 'lib/practica/menu.rb', line 24

def precio(coste)
    @total=coste[:precio]
    
end

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/practica/menu.rb', line 29

def to_s
    text = @name + "\n"
    for i in 0..@desc_menus.length-1 do
        text << "\t- #{@desc_menus[i]}\n"
        text << "\t\t#{@menu[i]}"
        text <<"\n"
        text << "\t\t#{@precios[i]} €\n"
    end
    text<<"\n#{@total}"
    text
end