Class: Alimento::MenuDSL

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

Overview

Menu formado por platos

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(desc, &block) ⇒ MenuDSL

Returns a new instance of MenuDSL.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/alimento/menu_dsl.rb', line 8

def initialize(desc, &block)
  @desc = desc
  @listaPlatos = []
  @listaPrecios = []
  @precio = 0.0

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/alimento/menu_dsl.rb', line 7

def name
  @name
end

Instance Method Details

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



25
26
27
28
29
30
# File 'lib/alimento/menu_dsl.rb', line 25

def componente(plato, options = {})
  unless options[:precio].nil?
    @listaPlatos << plato 
    @listaPrecios << options[:precio]
  end
end

#descripcion(desc) ⇒ Object



22
23
24
# File 'lib/alimento/menu_dsl.rb', line 22

def descripcion(desc)
  @desc = desc
end

#precio(value) ⇒ Object



31
32
33
# File 'lib/alimento/menu_dsl.rb', line 31

def precio(value)
  @precio = value
end

#to_sObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/alimento/menu_dsl.rb', line 34

def to_s
  count = 0
  ret = "Menu: #{@desc}\nPlatos:\n"
  ret + @listaPlatos.zip(@listaPrecios).map { 
    |x| "Plato #{count += 1}: "  + x.last.to_s + "€\n" +
    x.first.to_s +
      "\nValor nutricional: #{x.first.getValorCaloricoTotal}" +
      "\nValor ambiental: #{x.first.getEmisionGEI}"
  }.join("\n")
end