Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/tddAlimentos/menu.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plates ⇒ Object
Returns the value of attribute plates.
-
#prices ⇒ Object
Returns the value of attribute prices.
Instance Method Summary collapse
- #descripcion(description) ⇒ Object
-
#initialize(name, &block) ⇒ Menu
constructor
A new instance of Menu.
- #plato(options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Menu
Returns a new instance of Menu.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tddAlimentos/menu.rb', line 5 def initialize (name, &block) @name = name @description = "" @plates = [] @prices = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end @vct = (@plates.collect{ |plate| plate.vct }).sum.round(2) @gei = (@plates.collect{ |plate| plate.gei }).sum.round(2) @terrain = (@plates.collect{ |plate| plate.terrain }).sum.round(2) @price = @prices.sum end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/tddAlimentos/menu.rb', line 3 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/tddAlimentos/menu.rb', line 3 def name @name end |
#plates ⇒ Object
Returns the value of attribute plates.
3 4 5 |
# File 'lib/tddAlimentos/menu.rb', line 3 def plates @plates end |
#prices ⇒ Object
Returns the value of attribute prices.
3 4 5 |
# File 'lib/tddAlimentos/menu.rb', line 3 def prices @prices end |
Instance Method Details
#descripcion(description) ⇒ Object
27 28 29 |
# File 'lib/tddAlimentos/menu.rb', line 27 def descripcion (description) @description = description end |
#plato(options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/tddAlimentos/menu.rb', line 31 def plato ( = {}) @plates << [:valor] @prices << [:precio] end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tddAlimentos/menu.rb', line 36 def to_s str = "" str += @name + "\n" str += @description + "\n\n" @plates.each_with_index do |plate, index| str += (index + 1).to_s + ". " + plate.to_s + "\nPrecio: #{@prices[index]} €\n\n" end str += "Valor calorico total del menu: #{@vct} kcal\n" str += "GEI del menu: #{@gei}\n" str += "Uso de terreno del menu: #{@terrain}\n" str += "Precio total del menu: #{@price} €" end |