Created
January 24, 2019 11:50
-
-
Save ygorbarboza/93958d5f781cf57e55dfccdac471996e to your computer and use it in GitHub Desktop.
gist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ====================================== | |
// Gilded Rose Requirements Specification | |
// ====================================== | |
// We are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. | |
// We also buy and sell only the finest goods. | |
// Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We | |
// have a system in place that updates our inventory for us. | |
// First an introduction to our system: | |
// - All items have a SellIn value which denotes the number of days we have to sell the item | |
// - All items have a Quality value which denotes how valuable the item is | |
// - At the end of each day our system lowers both values for every item | |
// Pretty simple, right? Well this is where it gets interesting: | |
// - The Quality of an item is never negative | |
// - "Aged Brie" actually increases in Quality the older it gets | |
// - The Quality of an item is never more than 50 | |
// - "Sulfuras", being a legendary item, never has to be sold or decreases in Quality | |
// - "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches; | |
// Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a | |
// legendary item and as such its Quality is 80 and it never alters. | |
class GildedRose(object): | |
def __init__(self, items): | |
self.items = items | |
def update_quality(self): | |
for item in self.items: | |
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert": | |
if item.quality > 0: | |
if item.name != "Sulfuras, Hand of Ragnaros": | |
item.quality = item.quality - 1 | |
else: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.name == "Backstage passes to a TAFKAL80ETC concert": | |
if item.sell_in < 11: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.sell_in < 6: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
if item.name != "Sulfuras, Hand of Ragnaros": | |
item.sell_in = item.sell_in - 1 | |
if item.sell_in < 0: | |
if item.name != "Aged Brie": | |
if item.name != "Backstage passes to a TAFKAL80ETC concert": | |
if item.quality > 0: | |
if item.name != "Sulfuras, Hand of Ragnaros": | |
item.quality = item.quality - 1 | |
else: | |
item.quality = item.quality - item.quality | |
else: | |
if item.quality < 50: | |
item.quality = item.quality + 1 | |
class Item: | |
def __init__(self, name, sell_in, quality): | |
self.name = name | |
self.sell_in = sell_in | |
self.quality = quality | |
def __repr__(self): | |
return "%s, %s, %s" % (self.name, self.sell_in, self.quality) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment