mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Refactor: add handleQuality, handleSellIn of item classes
This commit is contained in:
parent
5d670ac672
commit
77c82c95b3
@ -9,12 +9,14 @@ export class GildedRose {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -29,6 +31,7 @@ export class GildedRose {
|
||||
}
|
||||
|
||||
handlePassesQuality(item) {
|
||||
//
|
||||
if (item.name !== ITEMS.PASSES) return;
|
||||
if (6 <= item.sellIn && item.sellIn < 11) {
|
||||
item.quality += 1;
|
||||
@ -40,6 +43,7 @@ export class GildedRose {
|
||||
}
|
||||
|
||||
handleQuality(item) {
|
||||
//
|
||||
switch (item.name) {
|
||||
case ITEMS.PASSES:
|
||||
this.handlePassesQuality(item);
|
||||
|
||||
@ -23,11 +23,12 @@ export class AgedBrie extends Item {
|
||||
super("Aged Brie", sellIn, quality);
|
||||
}
|
||||
handleQuality() {
|
||||
//
|
||||
this.quality++;
|
||||
this.quality++;
|
||||
}
|
||||
|
||||
handleSellIn() {
|
||||
//
|
||||
this.sellIn--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,11 +38,20 @@ export class Passes extends Item {
|
||||
}
|
||||
|
||||
handleQuality() {
|
||||
//
|
||||
this.quality--;
|
||||
|
||||
if (6 <= this.sellIn && this.sellIn < 11) {
|
||||
this.quality += 1;
|
||||
}
|
||||
|
||||
if (this.sellIn < 6) {
|
||||
this.quality += 2;
|
||||
}
|
||||
this.quality++;
|
||||
}
|
||||
|
||||
handleSellIn() {
|
||||
//
|
||||
this.sellIn--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +60,9 @@ 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