From 5a30f03ea4d76bc657a52d523a9c54ffb41c8f83 Mon Sep 17 00:00:00 2001 From: Anna Klimova Date: Thu, 4 Jan 2024 17:00:42 +0100 Subject: [PATCH] Refactor update_quality() by splitting into meaningful branches Use specific if-condition for every type of object. Do according actions inside. --- python/gilded_rose.py | 45 ++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/python/gilded_rose.py b/python/gilded_rose.py index 4f21ea64..9d511f7e 100755 --- a/python/gilded_rose.py +++ b/python/gilded_rose.py @@ -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: