Class: Menu

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/Menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dishes, prices) ⇒ Menu

Returns a new instance of Menu.



13
14
15
16
# File 'lib/Menu.rb', line 13

def initialize (name, dishes, prices)
    @name = name
    @dishes, @prices = dishes, prices
end

Instance Attribute Details

#dishesObject (readonly)

Returns the value of attribute dishes.



11
12
13
# File 'lib/Menu.rb', line 11

def dishes
  @dishes
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/Menu.rb', line 11

def name
  @name
end

#pricesObject (readonly)

Returns the value of attribute prices.



11
12
13
# File 'lib/Menu.rb', line 11

def prices
  @prices
end

Instance Method Details

#<=>(other) ⇒ Object

—- sobrecargas —



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Menu.rb', line 20

def <=>(other)
    return nil unless other.instance_of? Menu
    total_impact = 0
    total_price = 0
    other_impact = 0
    other_price = 0
          dishes.each { | dish | total_impact += (dish.terrainTotal + dish.dailygei) }
    other.dishes.each { | dish | other_impact += (dish.terrainTotal + dish.dailygei) }
          prices.each { | price | total_price += price }
    other.prices.each { | price | other_price += price }
    total_impact + total_price <=> other_impact + other_price   
end