Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/tddAlimentos/menu.rb', line 3

def description
  @description
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/tddAlimentos/menu.rb', line 3

def name
  @name
end

#platesObject

Returns the value of attribute plates.



3
4
5
# File 'lib/tddAlimentos/menu.rb', line 3

def plates
  @plates
end

#pricesObject

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 (options = {})
    @plates << options[:valor]
    @prices << options[:precio]
end

#to_sObject



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