Refactored GlidedRose class

This commit is contained in:
Kunnal-chawla 2025-12-28 10:02:09 +05:30
parent 561285edbd
commit 2947ff0f1b

View File

@ -1,4 +1,47 @@
# -*- coding: utf-8 -*-
# utf-8
class Updater(object):
MIN_QUALITY = 0
MAX_QUALITY = 50
def normal_item(self, item):
if item.sell_in > 0:
depreciation = -1
else:
depreciation = -2
item.quality = max((item.quality + depreciation), self.MIN_QUALITY)
item.sell_in += -1
def aged_brie(self, item):
if item.sell_in > 0:
appreciation = 1
else:
appreciation = 2
item.quality = min((item.quality + appreciation), self.MAX_QUALITY)
item.sell_in += -1
def sulfuras(self, item):
pass
def backstage_passes(self, item):
def get_quality(item, appreciation):
item.quality = min(item.quality + appreciation , self.MAX_QUALITY)
if item.sell_in > 10:
appreciation = 1
get_quality(item, appreciation)
elif item.sell_in > 5:
appreciation = 2
get_quality(item, appreciation)
elif item.sell_in > 0:
appreciation = 3
get_quality(item, appreciation)
else:
item.quality = 0
item.sell_in += -1
class GildedRose(object):
@ -6,34 +49,17 @@ class GildedRose(object):
self.items = items
def update_quality(self):
updater = Updater()
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
if item.name == 'Aged Brie':
updater.aged_brie(item)
elif item.name == 'Backstage passes to a TAFKAL80ETC concert':
updater.backstage_passes(item)
elif item.name == 'Sulfuras, Hand of Ragnaros':
updater.sulfuras(item)
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
updater.normal_item(item)
class Item: