mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Merge pull request #1 from bvsshanmukhanath/176864_coderefactoring
job id 176864 Gilded code refactoring challenge #339
This commit is contained in:
commit
48543f7e63
@ -2,41 +2,62 @@
|
|||||||
|
|
||||||
class GildedRose(object):
|
class GildedRose(object):
|
||||||
|
|
||||||
|
AGED_BRIE = "Aged Brie"
|
||||||
|
BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
||||||
|
CONJURED = "Conjured Mana Cake"
|
||||||
|
qualityIncrease = 1
|
||||||
|
|
||||||
def __init__(self, items):
|
def __init__(self, items):
|
||||||
self.items = items
|
self.items = items
|
||||||
|
|
||||||
def update_quality(self):
|
def update_quality(self):
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert":
|
self.update_item_quality(item)
|
||||||
if item.quality > 0:
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
def update_item_quality(self, item):
|
||||||
item.quality = item.quality - 1
|
isExpired = item.sell_in < 0
|
||||||
else:
|
qualityDecrease = self.determine_degrate_quality_rate(item,isExpired)
|
||||||
if item.quality < 50:
|
doesDegradeQaulity = item.name != self.AGED_BRIE and item.name != self.BACKSTAGE_PASSES and item.name != self.SULFURAS
|
||||||
item.quality = item.quality + 1
|
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
if doesDegradeQaulity:
|
||||||
if item.sell_in < 11:
|
self.adjust_quality(item, qualityDecrease)
|
||||||
if item.quality < 50:
|
|
||||||
item.quality = item.quality + 1
|
if item.name == self.AGED_BRIE:
|
||||||
if item.sell_in < 6:
|
qualityIncrease = 2 if isExpired else 1
|
||||||
if item.quality < 50:
|
self.adjust_quality(item, qualityIncrease)
|
||||||
item.quality = item.quality + 1
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
if item.name == self.BACKSTAGE_PASSES:
|
||||||
item.sell_in = item.sell_in - 1
|
self.update_backstagepasses_quality(item, isExpired)
|
||||||
if item.sell_in < 0:
|
|
||||||
if item.name != "Aged Brie":
|
if item.name != self.SULFURAS:
|
||||||
if item.name != "Backstage passes to a TAFKAL80ETC concert":
|
item.sell_in = item.sell_in - 1
|
||||||
if item.quality > 0:
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
# BAckstage Passes logic to update the item quality based on number of days
|
||||||
item.quality = item.quality - 1
|
def update_backstagepasses_quality(self, item, isExpired):
|
||||||
else:
|
self.adjust_quality(item, self.qualityIncrease)
|
||||||
item.quality = item.quality - item.quality
|
if item.sell_in < 11:
|
||||||
else:
|
self.adjust_quality(item, self.qualityIncrease)
|
||||||
if item.quality < 50:
|
if item.sell_in < 6:
|
||||||
item.quality = item.quality + 1
|
self.adjust_quality(item, self.qualityIncrease)
|
||||||
|
if isExpired:
|
||||||
|
item.quality = item.quality - item.quality
|
||||||
|
|
||||||
|
# Logic to determine the Quality Decrease rate based on Expired date and conjured item
|
||||||
|
def determine_degrate_quality_rate(self, item, isExpired):
|
||||||
|
qualityDecrease = -1 if item.name != self.CONJURED else -2
|
||||||
|
return qualityDecrease * 2 if isExpired else qualityDecrease
|
||||||
|
|
||||||
|
|
||||||
class Item:
|
# Update the quality item value if the quality value is within the range 0 to 50
|
||||||
|
def adjust_quality(self, item, quality_increase_decrease):
|
||||||
|
new_quality = item.quality + quality_increase_decrease
|
||||||
|
if new_quality >= 0 and new_quality <= 50:
|
||||||
|
item.quality = new_quality
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Item:
|
||||||
def __init__(self, name, sell_in, quality):
|
def __init__(self, name, sell_in, quality):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.sell_in = sell_in
|
self.sell_in = sell_in
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user