mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +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) {
|
handleSellIn(item) {
|
||||||
|
//
|
||||||
if (item.name != ITEMS.SURFRAS) {
|
if (item.name != ITEMS.SURFRAS) {
|
||||||
item.sellIn -= 1;
|
item.sellIn -= 1;
|
||||||
}
|
}
|
||||||
if (item.sellIn >= 0) return;
|
if (item.sellIn >= 0) return;
|
||||||
if (item.quality >= 50) return;
|
if (item.quality >= 50) return;
|
||||||
|
|
||||||
|
//
|
||||||
switch (item.name) {
|
switch (item.name) {
|
||||||
case ITEMS.BRIE:
|
case ITEMS.BRIE:
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
@ -29,6 +31,7 @@ export class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePassesQuality(item) {
|
handlePassesQuality(item) {
|
||||||
|
//
|
||||||
if (item.name !== ITEMS.PASSES) return;
|
if (item.name !== ITEMS.PASSES) return;
|
||||||
if (6 <= item.sellIn && item.sellIn < 11) {
|
if (6 <= item.sellIn && item.sellIn < 11) {
|
||||||
item.quality += 1;
|
item.quality += 1;
|
||||||
@ -40,6 +43,7 @@ export class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleQuality(item) {
|
handleQuality(item) {
|
||||||
|
//
|
||||||
switch (item.name) {
|
switch (item.name) {
|
||||||
case ITEMS.PASSES:
|
case ITEMS.PASSES:
|
||||||
this.handlePassesQuality(item);
|
this.handlePassesQuality(item);
|
||||||
|
|||||||
@ -23,11 +23,12 @@ export class AgedBrie extends Item {
|
|||||||
super("Aged Brie", sellIn, quality);
|
super("Aged Brie", sellIn, quality);
|
||||||
}
|
}
|
||||||
handleQuality() {
|
handleQuality() {
|
||||||
//
|
this.quality++;
|
||||||
|
this.quality++;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSellIn() {
|
handleSellIn() {
|
||||||
//
|
this.sellIn--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +38,20 @@ export class Passes extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleQuality() {
|
handleQuality() {
|
||||||
//
|
this.quality--;
|
||||||
|
|
||||||
|
if (6 <= this.sellIn && this.sellIn < 11) {
|
||||||
|
this.quality += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sellIn < 6) {
|
||||||
|
this.quality += 2;
|
||||||
|
}
|
||||||
|
this.quality++;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSellIn() {
|
handleSellIn() {
|
||||||
//
|
this.sellIn--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +60,9 @@ 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