Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Saarus gilded rose kata #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions python/gilded_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,42 @@ class GildedRose(object):
def __init__(self, items):
self.items = items

def update_sellin(self,item,num):
item.sell_in = item.sell_in + num

def set_quality(self,item,num):
item.quality = item.quality + num
if item.quality < 0:
item.quality = 0
elif (item.quality > 50):
item.quality = 50

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":
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
self.update_sellin(item,-1)
if item.name not in ["Aged Brie","Backstage passes to a TAFKAL80ETC concert","Sulfuras, Hand of Ragnaros","Conjured Mana Cake"]:
if (item.sell_in < 0):
self.set_quality(item,-2)
else:
self.set_quality(item,-1)
elif item.name in["Conjured Mana Cake"]:
if (item.sell_in < 0):
self.set_quality(item,-4)
else:
if item.quality < 50:
item.quality = item.quality + 1
self.set_quality(item,-2)
elif item.name in ["Aged Brie"]:
self.set_quality(item,1)
elif item.name in ["Backstage passes to a TAFKAL80ETC concert"]:
if (item.sell_in <=10 and item.sell_in > 5):
self.set_quality(item, 2)
elif (item.sell_in <=5 and item.sell_in > 0):
self.set_quality(item, 3)
elif (item.sell_in <= 0):
self.set_quality(item, -item.quality)
else:
self.set_quality(item,1)
elif item.name in ["Sulfuras, Hand of Ragnaros"]:
self.update_sellin(item,1) #re set sell in for legendary item


class Item:
Expand All @@ -44,3 +51,4 @@ def __init__(self, name, sell_in, quality):

def __repr__(self):
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)