mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Refactor: check test, delete previous functions
This commit is contained in:
parent
77c82c95b3
commit
b7857cb77b
@ -1,69 +1,19 @@
|
||||
import { ITEMS } from "./constants";
|
||||
import { Item } from "./itemClasses";
|
||||
import { AgedBrie, Passes, Surfras } from "./itemClasses";
|
||||
type ItemClasses = AgedBrie[] | Surfras[] | Passes[];
|
||||
|
||||
export class GildedRose {
|
||||
items: Array<Item>;
|
||||
|
||||
constructor(items = [] as Array<Item>) {
|
||||
items: ItemClasses;
|
||||
constructor(items = [] as ItemClasses) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
handleSellIn(item) {
|
||||
//
|
||||
if (item.name != ITEMS.SURFRAS) {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
if (item.sellIn >= 0) return;
|
||||
if (item.quality >= 50) return;
|
||||
|
||||
//
|
||||
switch (item.name) {
|
||||
case ITEMS.BRIE:
|
||||
item.quality = item.quality + 1;
|
||||
break;
|
||||
case ITEMS.SURFRAS:
|
||||
item.quality = 0;
|
||||
break;
|
||||
default:
|
||||
item.quality -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
handlePassesQuality(item) {
|
||||
//
|
||||
if (item.name !== ITEMS.PASSES) return;
|
||||
if (6 <= item.sellIn && item.sellIn < 11) {
|
||||
item.quality += 1;
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
item.quality += 2;
|
||||
}
|
||||
}
|
||||
|
||||
handleQuality(item) {
|
||||
//
|
||||
switch (item.name) {
|
||||
case ITEMS.PASSES:
|
||||
this.handlePassesQuality(item);
|
||||
break;
|
||||
case ITEMS.SURFRAS:
|
||||
item.quality -= 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.quality >= 50) return;
|
||||
item.quality += 1;
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
for (const item of this.items) {
|
||||
if (!item.quality) break;
|
||||
this.handleSellIn(item);
|
||||
this.handleQuality(item);
|
||||
}
|
||||
const updatedItems = this.items.map((item) => {
|
||||
item.handleQuality();
|
||||
|
||||
return this.items;
|
||||
item.handleSellIn();
|
||||
return item;
|
||||
});
|
||||
return updatedItems as ItemClasses;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,14 +8,6 @@ export class Item {
|
||||
this.sellIn = sellIn;
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
handleQuality() {
|
||||
//
|
||||
}
|
||||
|
||||
handleSellIn() {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
export class AgedBrie extends Item {
|
||||
@ -23,7 +15,7 @@ export class AgedBrie extends Item {
|
||||
super("Aged Brie", sellIn, quality);
|
||||
}
|
||||
handleQuality() {
|
||||
this.quality++;
|
||||
if (this.quality >= 50) return;
|
||||
this.quality++;
|
||||
}
|
||||
|
||||
@ -38,8 +30,6 @@ export class Passes extends Item {
|
||||
}
|
||||
|
||||
handleQuality() {
|
||||
this.quality--;
|
||||
|
||||
if (6 <= this.sellIn && this.sellIn < 11) {
|
||||
this.quality += 1;
|
||||
}
|
||||
@ -60,9 +50,7 @@ export class Surfras extends Item {
|
||||
super("Sulfuras, Hand of Ragnaros", sellIn, quality);
|
||||
}
|
||||
handleQuality() {
|
||||
this.quality = 0;
|
||||
this.quality--;
|
||||
this.quality++;
|
||||
//
|
||||
}
|
||||
|
||||
handleSellIn() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user