mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Extract update item quality
This commit is contained in:
parent
a06e221197
commit
426d9ecd03
@ -19,27 +19,33 @@ export class GildedRose {
|
||||
|
||||
updateQuality() {
|
||||
this.items.forEach((item, i) => {
|
||||
if (item.name === 'Sulfuras, Hand of Ragnaros') {
|
||||
// Do Nothing
|
||||
} else if (item.name == 'Aged Brie') {
|
||||
this.incrementQuality(item);
|
||||
} else if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
this.incrementQuality(item);
|
||||
if (item.sellIn < 11) this.incrementQuality(item)
|
||||
if (item.sellIn < 6) this.incrementQuality(item)
|
||||
} else if (item.quality > 0) {
|
||||
item.quality = item.quality - 1
|
||||
}
|
||||
this.updateItemQuality(item)
|
||||
|
||||
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
||||
item.sellIn = item.sellIn - 1;
|
||||
}
|
||||
|
||||
item.quality = sellInBelow0(item)
|
||||
})
|
||||
|
||||
return this.items;
|
||||
|
||||
}
|
||||
|
||||
private updateItemQuality(item: Item) {
|
||||
if (item.name === 'Sulfuras, Hand of Ragnaros') {
|
||||
return
|
||||
} else if (item.name == 'Aged Brie') {
|
||||
this.incrementQuality(item);
|
||||
} else if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
this.incrementQuality(item);
|
||||
if (item.sellIn < 11) this.incrementQuality(item)
|
||||
if (item.sellIn < 6) this.incrementQuality(item)
|
||||
} else if (item.quality > 0) {
|
||||
item.quality = item.quality - 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private incrementQuality(item: Item) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user