mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +00:00
2. Extracted monolithic update_quality into focused methods
This commit is contained in:
parent
5d1bb3cee1
commit
273ed6aa7c
@ -1,40 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
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":
|
||||
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
|
||||
self.update_item_quality(item)
|
||||
self.update_sell_in(item)
|
||||
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
|
||||
self.handle_expired_item(item)
|
||||
|
||||
def update_item_quality(self, item):
|
||||
if item.name == "Aged Brie":
|
||||
self.update_aged_brie(item)
|
||||
elif item.name == "Backstage passes to a TAFKAL80ETC concert":
|
||||
self.update_backstage_pass(item)
|
||||
elif item.name != "Sulfuras, Hand of Ragnaros":
|
||||
self.update_normal_item(item)
|
||||
|
||||
def update_sell_in(self, item):
|
||||
if item.name != "Sulfuras, Hand of Ragnaros":
|
||||
item.sell_in -= 1
|
||||
|
||||
def handle_expired_item(self, item):
|
||||
if item.name == "Aged Brie":
|
||||
self.increase_quality(item)
|
||||
elif item.name == "Backstage passes to a TAFKAL80ETC concert":
|
||||
item.quality = 0
|
||||
elif item.name != "Sulfuras, Hand of Ragnaros":
|
||||
self.decrease_quality(item)
|
||||
|
||||
def update_aged_brie(self, item):
|
||||
self.increase_quality(item)
|
||||
|
||||
def update_backstage_pass(self, item):
|
||||
self.increase_quality(item)
|
||||
if item.sell_in < 11:
|
||||
self.increase_quality(item)
|
||||
if item.sell_in < 6:
|
||||
self.increase_quality(item)
|
||||
|
||||
def update_normal_item(self, item):
|
||||
self.decrease_quality(item)
|
||||
|
||||
def increase_quality(self, item):
|
||||
if item.quality < 50:
|
||||
item.quality += 1
|
||||
|
||||
def decrease_quality(self, item):
|
||||
if item.quality > 0:
|
||||
item.quality -= 1
|
||||
|
||||
class Item:
|
||||
def __init__(self, name, sell_in, quality):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user