mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-10-13 17:49:25 +00:00
Extract constants and return early for Sulfuras
No behaviour change. Named the item strings and the 0/50 bounds, moved the body into _update_item and return early for Sulfuras so the rest of the ladder only deals with items that actually change.
This commit is contained in:
1 parent
3809be0b03
commit
19011580f5
1 file changed
+39
-25
+39
-25
@@ -1,5 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
AGED_BRIE = "Aged Brie"
|
||||
BACKSTAGE_PASS = "Backstage passes to a TAFKAL80ETC concert"
|
||||
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
||||
|
||||
MIN_QUALITY = 0
|
||||
MAX_QUALITY = 50
|
||||
|
||||
|
||||
class GildedRose(object):
|
||||
|
||||
def __init__(self, items):
|
||||
@@ -7,33 +15,39 @@ class GildedRose(object):
|
||||
|
||||
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":
|
||||
self._update_item(item)
|
||||
|
||||
@staticmethod
|
||||
def _update_item(item):
|
||||
if item.name == SULFURAS:
|
||||
return # legendary: never has to be sold and never changes
|
||||
|
||||
if item.name != AGED_BRIE and item.name != BACKSTAGE_PASS:
|
||||
if item.quality > MIN_QUALITY:
|
||||
item.quality = item.quality - 1
|
||||
else:
|
||||
if item.quality < MAX_QUALITY:
|
||||
item.quality = item.quality + 1
|
||||
if item.name == BACKSTAGE_PASS:
|
||||
if item.sell_in < 11:
|
||||
if item.quality < MAX_QUALITY:
|
||||
item.quality = item.quality + 1
|
||||
if item.sell_in < 6:
|
||||
if item.quality < MAX_QUALITY:
|
||||
item.quality = item.quality + 1
|
||||
|
||||
item.sell_in = item.sell_in - 1
|
||||
|
||||
if item.sell_in < 0:
|
||||
if item.name != AGED_BRIE:
|
||||
if item.name != BACKSTAGE_PASS:
|
||||
if item.quality > MIN_QUALITY:
|
||||
item.quality = item.quality - 1
|
||||
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
|
||||
item.quality = MIN_QUALITY
|
||||
else:
|
||||
if item.quality < MAX_QUALITY:
|
||||
item.quality = item.quality + 1
|
||||
|
||||
|
||||
class Item:
|
||||
|
||||
Reference in new issue
Block a user