mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Create smaller submethods to update items fields
This commit is contained in:
parent
5a30f03ea4
commit
ba27c89b42
@ -5,32 +5,43 @@ class GildedRose(object):
|
|||||||
def __init__(self, items):
|
def __init__(self, items):
|
||||||
self.items = items
|
self.items = items
|
||||||
|
|
||||||
|
def _update_aged_brie(self, item):
|
||||||
|
if item.quality < 50:
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
if item.sell_in < 0:
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
item.sell_in = + 1
|
||||||
|
|
||||||
|
def _update_backstage_passes(self, item):
|
||||||
|
if item.quality < 50:
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
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
|
||||||
|
item.sell_in = + 1
|
||||||
|
|
||||||
|
def _update_simple_item(self, item):
|
||||||
|
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
|
||||||
|
|
||||||
def update_quality(self):
|
def update_quality(self):
|
||||||
|
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
if item.name == "Backstage passes to a TAFKAL80ETC concert":
|
||||||
if item.quality < 50:
|
self._update_backstage_passes(item)
|
||||||
item.quality = item.quality + 1
|
|
||||||
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":
|
elif item.name == "Aged Brie":
|
||||||
if item.quality < 50:
|
self._update_aged_brie(item)
|
||||||
item.quality = item.quality + 1
|
|
||||||
if item.sell_in < 0:
|
|
||||||
item.quality = item.quality + 1
|
|
||||||
elif item.name == "Sulfuras, Hand of Ragnaros":
|
elif item.name == "Sulfuras, Hand of Ragnaros":
|
||||||
item.quality = 80
|
pass
|
||||||
else:
|
else:
|
||||||
if item.quality > 0:
|
self._update_simple_item(item)
|
||||||
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:
|
class Item:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user