GildedRose-Refactoring-Kata/python/gilded_rose.py
Daniel Vu 0c5f5dca75 Adds support for conjured items
To avoid the goblin one-shotting me, I've extended his/her/their class
instead so we could add a `conjured` attribute. A decision was made to
fix the tests as as and add test coverage in future commits, for the
sake of treating this as a short exercise that shouldn't take more than
a couple of hours.
2021-04-05 15:21:07 -04:00

66 lines
2.4 KiB
Python
Executable File

# -*- coding: utf-8 -*-
def handle_normal_deprecation(item):
try:
if item.conjured:
item.quality = item.quality - 2
else:
item.quality = item.quality - 1
except AttributeError: # Item cannot be conjured.
item.quality = item.quality - 1
class GildedRose(object):
def __init__(self, items):
self.items = items
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":
handle_normal_deprecation(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":
handle_normal_deprecation(item)
else:
item.quality = item.quality - item.quality
else:
if item.quality < 50:
item.quality = item.quality + 1
class Item(object):
def __init__(self, name, sell_in, quality):
self.name = name
self.sell_in = sell_in
self.quality = quality
def __repr__(self):
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)
class BaseItem(Item):
def __init__(self, conjured=False, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.conjured = conjured
def __repr__(self):
return "%s, %s, %s, %s" % (self.name, self.sell_in, self.quality, self.conjured)