Refactor update_quality() by splitting into meaningful branches

Use specific if-condition for every type of object. Do according
actions inside.
This commit is contained in:
Anna Klimova 2024-01-04 17:00:42 +01:00
parent a759630e00
commit 5a30f03ea4

View File

@ -6,34 +6,31 @@ class GildedRose(object):
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.name == "Backstage passes to a TAFKAL80ETC concert":
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:
if item.sell_in < 11:
item.quality = item.quality + 1
if item.sell_in < 6:
item.quality = item.quality + 1
if item.sell_in <= 0:
item.quality = 0
elif item.name == "Aged Brie":
if item.quality < 50:
item.quality = item.quality + 1
if item.sell_in < 0:
item.quality = item.quality + 1
elif item.name == "Sulfuras, Hand of Ragnaros":
item.quality = 80
else:
if item.quality > 0:
item.quality = item.quality - 1
item.sell_in = item.sell_in - 1
if item.sell_in < 0:
if item.quality > 0:
item.quality = item.quality - 1
class Item: