Skip to content

Commit

Permalink
Decorator Added
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarMichelH committed Oct 24, 2018
1 parent d3f72b5 commit 21ed672
Showing 1 changed file with 167 additions and 0 deletions.
167 changes: 167 additions & 0 deletions decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
class Bebida
@cost = 0
@description = ""

def cost
@cost
end

def description
@description
end
end

class CondimentDecorator < Bebida
@cost = 0
@description = ""
end

class HouseBlen < Bebida
def initialize
@cost = 12
@description = "HouseBlen $12\nCondimentos:\n"
end
end

class DarkRoast < Bebida
def initialize
@cost = 13
@description = "DarkRoast $13\nCondimentos:\n"
end
end

class Espresso < Bebida
def initialize
@cost = 10
@description = "Espresso $10\nCondimentos:\n"
end
end

class Decaf < Bebida
def initialize
@cost = 9
@description = "Decaf $9\nCondimentos:\n"
end
end

##Condiments

class Leche < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + "Lechita $2\n"
end

def cost
2 + bebida.cost
end
end

class LecheDeslactosada < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + "Lechita Desclatosada $1\n"
end

def cost
1 + bebida.cost
end
end

class LecheLight < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + "Lechita Light $2\n"
end

def cost
2 + bebida.cost
end
end

class LecheDesclatosadaLight < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + "Lechita Desclatosada Light $3\n"
end

def cost
3 + bebida.cost
end
end

class Mocha < CondimentDecorator
@bebida = Bebida.new

def initialize(bebida)
@bebida = bebida
end

def description
@bebida.description + "Mocha $4\n"
end

def cost
4 + @bebida.cost
end
end

class LecheSoya < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + "Lechita Soya $5\n"
end

def cost
5 + bebida.cost
end
end

class Crema < CondimentDecorator
bebida = Bebida.new

def initialize(bebida)
self.bebida = bebida
end

def description
bebida.description + " Crema $0.5\n"
end

def cost
0.5 + bebida.cost
end
end

bebida = Espresso.new
bebida = Mocha.new(bebida)
bebida = Mocha.new(bebida)
bebida = Mocha.new(bebida)

puts bebida.description
puts "Costo total: $" + bebida.cost.to_s

0 comments on commit 21ed672

Please sign in to comment.