From 0e4a0b0fac98b1a683393e38651c373fd0c7160e Mon Sep 17 00:00:00 2001 From: Vasu Bhatia Date: Sun, 7 Dec 2025 18:20:27 +0000 Subject: [PATCH] Add helper methods for quality management --- python/gilded_rose.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/python/gilded_rose.py b/python/gilded_rose.py index 9a1f48e2..a1fe25e0 100755 --- a/python/gilded_rose.py +++ b/python/gilded_rose.py @@ -33,6 +33,32 @@ class GildedRose: """ self.items = items + def _increase_quality(self, item: Item, amount: int = 1) -> None: + """Increase the quality of an item, ensuring it does not exceed MAX_QUALITY. + + Parameters + ---------- + item : Item + The item whose quality is to be increased. + amount : int, optional + The amount to increase the quality by (default is 1). + + """ + item.quality = min(MAX_QUALITY, item.quality + amount) + + def _decrease_quality(self, item: Item, amount: int = 1) -> None: + """Decrease the quality of an item, ensuring it does not go below MIN_QUALITY. + + Parameters + ---------- + item : Item + The item whose quality is to be decreased. + amount : int, optional + The amount to decrease the quality by (default is 1). + + """ + item.quality = max(MIN_QUALITY, item.quality - amount) + def update_quality(self) -> None: """Update quality and sell_in for all items according to the business rules.""" for item in self.items: