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 { AgedBrie, Passes, Surfras } from "./itemClasses";
|
||||||
import { Item } from "./itemClasses";
|
type ItemClasses = AgedBrie[] | Surfras[] | Passes[];
|
||||||
|
|
||||||
export class GildedRose {
|
export class GildedRose {
|
||||||
items: Array<Item>;
|
items: ItemClasses;
|
||||||
|
constructor(items = [] as ItemClasses) {
|
||||||
constructor(items = [] as Array<Item>) {
|
|
||||||
this.items = items;
|
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() {
|
updateQuality() {
|
||||||
for (const item of this.items) {
|
const updatedItems = this.items.map((item) => {
|
||||||
if (!item.quality) break;
|
item.handleQuality();
|
||||||
this.handleSellIn(item);
|
|
||||||
this.handleQuality(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.items;
|
item.handleSellIn();
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
return updatedItems as ItemClasses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,14 +8,6 @@ export class Item {
|
|||||||
this.sellIn = sellIn;
|
this.sellIn = sellIn;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleQuality() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSellIn() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AgedBrie extends Item {
|
export class AgedBrie extends Item {
|
||||||
@ -23,7 +15,7 @@ export class AgedBrie extends Item {
|
|||||||
super("Aged Brie", sellIn, quality);
|
super("Aged Brie", sellIn, quality);
|
||||||
}
|
}
|
||||||
handleQuality() {
|
handleQuality() {
|
||||||
this.quality++;
|
if (this.quality >= 50) return;
|
||||||
this.quality++;
|
this.quality++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,8 +30,6 @@ export class Passes extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleQuality() {
|
handleQuality() {
|
||||||
this.quality--;
|
|
||||||
|
|
||||||
if (6 <= this.sellIn && this.sellIn < 11) {
|
if (6 <= this.sellIn && this.sellIn < 11) {
|
||||||
this.quality += 1;
|
this.quality += 1;
|
||||||
}
|
}
|
||||||
@ -60,9 +50,7 @@ export class Surfras extends Item {
|
|||||||
super("Sulfuras, Hand of Ragnaros", sellIn, quality);
|
super("Sulfuras, Hand of Ragnaros", sellIn, quality);
|
||||||
}
|
}
|
||||||
handleQuality() {
|
handleQuality() {
|
||||||
this.quality = 0;
|
//
|
||||||
this.quality--;
|
|
||||||
this.quality++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSellIn() {
|
handleSellIn() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user