Class: DSLMenu
- Inherits:
-
Object
- Object
- DSLMenu
- Defined in:
- lib/DSLMenu.rb
Instance Attribute Summary collapse
-
#menu(descripcion, opciones = {}) ⇒ Object
Returns the value of attribute menu.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
-
#platos ⇒ Object
Returns the value of attribute platos.
Instance Method Summary collapse
-
#initialize(nombre, &block) ⇒ DSLMenu
constructor
A new instance of DSLMenu.
- #plato(nombre, opciones = {}) ⇒ Object
- #to_s ⇒ Object
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
#menu(descripcion, opciones = {}) ⇒ Object
Returns the value of attribute menu.
3 4 5 |
# File 'lib/DSLMenu.rb', line 3 def @menu end |
#nombre ⇒ Object
Returns the value of attribute nombre.
3 4 5 |
# File 'lib/DSLMenu.rb', line 3 def nombre @nombre end |
#platos ⇒ Object
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_s ⇒ Object
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 || output << "#{}" end output << "\n\n" @platos.each_with_index do |plato, i| output << "[#{i + 1}] #{plato}\n" end output << "\n\n\n" output end |