mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-20 00:41:07 +00:00
Extract update item quality
This commit is contained in:
parent
a06e221197
commit
426d9ecd03
@ -19,27 +19,33 @@ export class GildedRose {
|
|||||||
|
|
||||||
updateQuality() {
|
updateQuality() {
|
||||||
this.items.forEach((item, i) => {
|
this.items.forEach((item, i) => {
|
||||||
if (item.name === 'Sulfuras, Hand of Ragnaros') {
|
this.updateItemQuality(item)
|
||||||
// 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
|
|
||||||
}
|
|
||||||
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.quality = sellInBelow0(item)
|
item.quality = sellInBelow0(item)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.items;
|
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) {
|
private incrementQuality(item: Item) {
|
||||||
if (item.quality < 50) {
|
if (item.quality < 50) {
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user