mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
segmentation per product
This commit is contained in:
parent
f322e70f1e
commit
0dcccbe6c4
@ -12,7 +12,6 @@ export class Item {
|
||||
|
||||
static maxQualityThreshold = 50
|
||||
static minQualityThreshold = 0
|
||||
static legendaryQuality = 80
|
||||
}
|
||||
|
||||
export class GildedRose {
|
||||
@ -27,8 +26,12 @@ export class GildedRose {
|
||||
return item.sellIn < 0
|
||||
}
|
||||
|
||||
shouldDecreaseQuality(item: Item) {
|
||||
return item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert'
|
||||
isNormalProduct(item: Item) {
|
||||
return (
|
||||
item.name !== 'Aged Brie' &&
|
||||
item.name !== 'Backstage passes to a TAFKAL80ETC concert' &&
|
||||
item.name !== 'Sulfuras, Hand of Ragnaros'
|
||||
)
|
||||
}
|
||||
|
||||
isLegendayProduct(item: Item) {
|
||||
@ -43,47 +46,67 @@ export class GildedRose {
|
||||
}
|
||||
|
||||
decrementQuality(item: Item) {
|
||||
if (item.quality > Item.minQualityThreshold) {
|
||||
return item.quality - 1
|
||||
if (item.quality <= Item.minQualityThreshold) {
|
||||
return item.quality
|
||||
}
|
||||
return item.quality
|
||||
return item.quality - 1
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
this.items.forEach(item => {
|
||||
//LEGENDARY
|
||||
if (this.isLegendayProduct(item)) {
|
||||
item.quality = 80
|
||||
return
|
||||
}
|
||||
const currentProductName = item.name
|
||||
// PART 1
|
||||
if (this.shouldDecreaseQuality(item)) {
|
||||
item.quality = this.decrementQuality(item)
|
||||
} else {
|
||||
item.quality = this.incrementQuality(item)
|
||||
if (currentProductName === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (item.sellIn < 11) {
|
||||
item.quality = this.incrementQuality(item)
|
||||
}
|
||||
if (item.sellIn < 6) {
|
||||
item.quality = this.incrementQuality(item)
|
||||
}
|
||||
|
||||
// NORMAL PRODUCT
|
||||
if (this.isNormalProduct(item)) {
|
||||
item.sellIn = item.sellIn - 1
|
||||
|
||||
if (this.isOutdated(item)) {
|
||||
item.quality = this.decrementQuality(item)
|
||||
item.quality = this.decrementQuality(item)
|
||||
return
|
||||
}
|
||||
}
|
||||
// part 2
|
||||
item.sellIn = item.sellIn - 1
|
||||
// part 3
|
||||
if (!this.isOutdated(item)) {
|
||||
|
||||
item.quality = this.decrementQuality(item)
|
||||
return
|
||||
}
|
||||
|
||||
if (currentProductName !== 'Aged Brie') {
|
||||
if (currentProductName !== 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
item.quality = this.decrementQuality(item)
|
||||
} else {
|
||||
item.quality = item.quality - item.quality
|
||||
}
|
||||
} else {
|
||||
// BACKSTAGE
|
||||
if (currentProductName === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
item.quality = this.incrementQuality(item)
|
||||
|
||||
if (item.sellIn < 11) {
|
||||
item.quality = this.incrementQuality(item)
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
item.quality = this.incrementQuality(item)
|
||||
}
|
||||
|
||||
item.sellIn = item.sellIn - 1
|
||||
|
||||
if (item.sellIn <= 0) {
|
||||
item.quality = 0
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AGED BRIE
|
||||
if (currentProductName === 'Aged Brie') {
|
||||
item.quality = this.incrementQuality(item)
|
||||
item.sellIn = item.sellIn - 1
|
||||
if (!this.isOutdated(item)) {
|
||||
return
|
||||
}
|
||||
|
||||
item.quality = this.incrementQuality(item)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user