mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 14:11:20 +00:00
Merge pull request #2 from zoengsw/refactor-gildedrose
Refactor gildedrose
This commit is contained in:
commit
821867f148
@ -1,39 +1,46 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
class GildedRose(object):
|
class GildedRose(object):
|
||||||
|
BACKSTAGE = 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
|
SULFURAS = 'Sulfuras, Hand of Ragnaros'
|
||||||
|
AGED_BRIE = 'Aged Brie'
|
||||||
|
MAX_QUAL = 50
|
||||||
|
|
||||||
def __init__(self, items):
|
def __init__(self, items):
|
||||||
self.items = items
|
self.items = items
|
||||||
|
|
||||||
|
def __qual_inc(self, item, inc):
|
||||||
|
item.quality = min(self.MAX_QUAL, item.quality + inc)
|
||||||
|
|
||||||
|
def __qual_dec(self, item, dec):
|
||||||
|
item.quality = max(0, item.quality - dec)
|
||||||
|
|
||||||
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":
|
match item.name:
|
||||||
if item.quality > 0:
|
case self.AGED_BRIE:
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
if item.sell_in > 0:
|
||||||
item.quality = item.quality - 1
|
self.__qual_inc(item, 1)
|
||||||
else:
|
else:
|
||||||
if item.quality < 50:
|
self.__qual_inc(item, 2)
|
||||||
item.quality = item.quality + 1
|
case self.SULFURAS:
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
pass
|
||||||
if item.sell_in < 11:
|
case self.BACKSTAGE:
|
||||||
if item.quality < 50:
|
if item.sell_in > 10:
|
||||||
item.quality = item.quality + 1
|
self.__qual_inc(item, 1)
|
||||||
if item.sell_in < 6:
|
elif item.sell_in > 5:
|
||||||
if item.quality < 50:
|
self.__qual_inc(item, 2)
|
||||||
item.quality = item.quality + 1
|
elif item.sell_in > 0:
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
self.__qual_inc(item, 3)
|
||||||
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:
|
else:
|
||||||
item.quality = item.quality - item.quality
|
item.quality = 0
|
||||||
|
case _:
|
||||||
|
if item.sell_in > 0:
|
||||||
|
self.__qual_dec(item, 1)
|
||||||
else:
|
else:
|
||||||
if item.quality < 50:
|
self.__qual_dec(item, 2)
|
||||||
item.quality = item.quality + 1
|
if not item.name == self.SULFURAS:
|
||||||
|
item.sell_in -= 1
|
||||||
|
|
||||||
|
|
||||||
class Item:
|
class Item:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user