Class: Comida::Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &block) ⇒ Menu

Returns a new instance of Menu.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/comida/menu.rb', line 22

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

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

Instance Attribute Details

#descripcion(descrip) ⇒ Object (readonly)

Returns the value of attribute descripcion.



20
21
22
# File 'lib/comida/menu.rb', line 20

def descripcion
  @descripcion
end

#nombreObject (readonly)

Returns the value of attribute nombre.



20
21
22
# File 'lib/comida/menu.rb', line 20

def nombre
  @nombre
end

#platosObject (readonly)

Returns the value of attribute platos.



20
21
22
# File 'lib/comida/menu.rb', line 20

def platos
  @platos
end

#precio_total(precio) ⇒ Object (readonly)

Returns the value of attribute precio_total.



20
21
22
# File 'lib/comida/menu.rb', line 20

def precio_total
  @precio_total
end

#preciosObject (readonly)

Returns the value of attribute precios.



20
21
22
# File 'lib/comida/menu.rb', line 20

def precios
  @precios
end

#v_ambientalObject (readonly)

Returns the value of attribute v_ambiental.



20
21
22
# File 'lib/comida/menu.rb', line 20

def v_ambiental
  @v_ambiental
end

#v_nutricionalObject (readonly)

Returns the value of attribute v_nutricional.



20
21
22
# File 'lib/comida/menu.rb', line 20

def v_nutricional
  @v_nutricional
end

Instance Method Details

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



39
40
41
42
43
44
45
46
# File 'lib/comida/menu.rb', line 39

def plato(nombre, options = {})
  plato = nombre
  plato << "(#{options[:descripcion]})" if options[:descripcion]
  plato << "(#{options[:cantidad]})" if options[:cantidad]
  plato << "(#{options[:precio]})" if options[:precio]

  @platos << plato
end

#preparacion(descripcion, options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/comida/menu.rb', line 48

def preparacion(descripcion, options = {})
  preparar = descripcion
  preparar << "(#{options[:duracion]})" if options[:duracion]

  @platos << preparar
end

#to_sObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/comida/menu.rb', line 67

def to_s
  output = @nombre
  output << "\n#{'=' * @nombre.size}\n\n"
  output << "Platos : \n\n"

  @platos.each_with_index do |plato, index|
    output << "#{index + 1}) #{plato[:descripcion]}, #{plato[:cantidad]}, #{plato[:precio]}\n"
  end

  output
end

#valor_ambiental(valor) ⇒ Object



63
64
65
# File 'lib/comida/menu.rb', line 63

def valor_ambiental(valor)
  @v_ambiental = valor
end

#valor_nutricional(valor) ⇒ Object



59
60
61
# File 'lib/comida/menu.rb', line 59

def valor_nutricional(valor)
  @v_nutricional = valor
end