Class: Alimento::MenuDSL
- Inherits:
-
Object
- Object
- Alimento::MenuDSL
- Defined in:
- lib/alimento/menu_dsl.rb
Overview
Menu formado por platos
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #componente(plato, options = {}) ⇒ Object
- #descripcion(desc) ⇒ Object
-
#initialize(desc, &block) ⇒ MenuDSL
constructor
A new instance of MenuDSL.
- #precio(value) ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object (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, = {}) unless [:precio].nil? @listaPlatos << plato @listaPrecios << [: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_s ⇒ Object
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 |