From b0580cba9b51af0b0f5f711422d02fce2fbb66d2 Mon Sep 17 00:00:00 2001 From: Naren2055 Date: Sun, 16 Feb 2025 07:14:56 -0800 Subject: [PATCH] 'refactoring' --- pyproject.toml | 2 ++ python/components/gilded_rose.py | 10 +++++----- python/models/items.py | 1 + python/src/aged_brie.py | 4 ++-- python/src/backstage_passes.py | 4 ++-- python/src/conjured.py | 5 ++--- python/src/main.py | 24 ++++++++++++++++-------- python/src/normal_item_logic.py | 4 ++-- python/src/sulfuras.py | 4 ++-- 9 files changed, 34 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ed1db6ba..8205bd4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,5 @@ +package-mode = false + [tool.poetry] name = "gildedrose" version = "1" diff --git a/python/components/gilded_rose.py b/python/components/gilded_rose.py index be2b14d7..17b00c1a 100644 --- a/python/components/gilded_rose.py +++ b/python/components/gilded_rose.py @@ -1,11 +1,11 @@ from abc import abstractmethod, ABC +from pydantic import BaseModel -class Item: - def __init__(self, name, sell_in, quality): - self.name = name - self.sell_in = sell_in - self.quality = quality +class Item(BaseModel): + name : str + sell_in : int + quality : int class GildedRose(ABC): def __init__(self, items: Item): diff --git a/python/models/items.py b/python/models/items.py index 3d36e0cb..1af445f4 100644 --- a/python/models/items.py +++ b/python/models/items.py @@ -4,3 +4,4 @@ class Items(Enum): aged_brie = "Aged Brie" sulfuras = "Sulfuras" backstage_passes = "Backstage Passes" + conjured = "Conjured" diff --git a/python/src/aged_brie.py b/python/src/aged_brie.py index b0bb4ef9..c3546d0c 100644 --- a/python/src/aged_brie.py +++ b/python/src/aged_brie.py @@ -3,8 +3,8 @@ from python.components.gilded_rose import GildedRose, Item class AgedBrieLogic(GildedRose): - def __init__(self, name, quality, sell_in): - super().__init__(Item(name, quality, sell_in)) + def __init__(self, item: Item): + super().__init__(item) def update_quality(self): if self.quality < 50: diff --git a/python/src/backstage_passes.py b/python/src/backstage_passes.py index 8481680c..f9960643 100644 --- a/python/src/backstage_passes.py +++ b/python/src/backstage_passes.py @@ -2,8 +2,8 @@ from python.components.gilded_rose import GildedRose, Item class BackstagePassesLogic(GildedRose): - def __init__(self, name, quality, sell_in): - super().__init__(Item(name, quality, sell_in)) + def __init__(self, item: Item): + super().__init__(item) def update_quality(self): if self.quality < 50: diff --git a/python/src/conjured.py b/python/src/conjured.py index e0ce5109..a06a2e18 100644 --- a/python/src/conjured.py +++ b/python/src/conjured.py @@ -4,9 +4,8 @@ from python.components.gilded_rose import GildedRose, Item class ConjuredItem(GildedRose): - - def __init__(self, name, quality, sell_in): - super().__init__(Item(name, quality, sell_in)) + def __init__(self, item: Item): + super().__init__(item) def update_quality(self): if self.quality > 0: diff --git a/python/src/main.py b/python/src/main.py index 870e2a62..e81679e7 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -1,18 +1,26 @@ from python.src.aged_brie import AgedBrieLogic from python.src.backstage_passes import BackstagePassesLogic +from python.src.conjured import ConjuredItem from python.src.normal_item_logic import NormalItemLogic from python.src.sulfuras import SulfurasLogic +from python.models.items import Items +from python.components.gilded_rose import Item class UpdateItemLogic: @staticmethod - def update_items(items): + def update_items(items: list[Item]): + quality, sell_in = None, None # initializing values for item in items: - if item.name == "Aged Brie": - AgedBrieLogic.update_quality(item) - elif item.name == "Backstage passes to a TAFKAL80ETC concert": - BackstagePassesLogic.update_quality(item) - elif item.name == "Sulfuras, Hand of Ragnaros": - SulfurasLogic.update_quality(item) + if item.name == item.aged_brie: + quality, sell_in = AgedBrieLogic(item).update_quality() + elif item.name == Item.backstage_passes: + quality, sell_in = BackstagePassesLogic(item).update_quality() + elif item.name == Item.sulfuras: + quality, sell_in = SulfurasLogic(item).update_quality() + elif item.name == Item.conjured: + quality, sell_in = ConjuredItem(item).update_quality() else: - NormalItemLogic.update_quality(item) \ No newline at end of file + quality, sell_in = NormalItemLogic(item).update_quality() + + return quality, sell_in \ No newline at end of file diff --git a/python/src/normal_item_logic.py b/python/src/normal_item_logic.py index f29c51f5..99ed7554 100644 --- a/python/src/normal_item_logic.py +++ b/python/src/normal_item_logic.py @@ -2,8 +2,8 @@ from python.components.gilded_rose import GildedRose, Item class NormalItemLogic(GildedRose): - def __init__(self, name, quality, sell_in): - super().__init__(Item(name, quality, sell_in)) + def __init__(self, item: Item): + super().__init__(item) def update_quality(self): if self.quality > 0: diff --git a/python/src/sulfuras.py b/python/src/sulfuras.py index 5ecd1c08..37c80e8f 100644 --- a/python/src/sulfuras.py +++ b/python/src/sulfuras.py @@ -2,8 +2,8 @@ from python.components.gilded_rose import GildedRose, Item class SulfurasLogic(GildedRose): - def __init__(self, name, quality, sell_in): - super().__init__(Item(name, quality, sell_in)) + def __init__(self, item: Item): + super().__init__(item) def update_quality(self): # "Sulfuras" does not change in quality or sell_in