mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Refactor to get quality change for each item
This commit is contained in:
parent
9111104f97
commit
a3f6b9a668
@ -13,19 +13,24 @@ class Shop {
|
|||||||
|
|
||||||
_updateItem(item) {
|
_updateItem(item) {
|
||||||
this._updateItemQuality(item);
|
this._updateItemQuality(item);
|
||||||
this._updateItemSellIn(item)
|
|
||||||
this._checkMaxQuality(item);
|
this._checkMaxQuality(item);
|
||||||
this._checkMinQuality(item);
|
this._checkMinQuality(item);
|
||||||
|
this._updateItemSellIn(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateItemQuality(item) {
|
_updateItemQuality(item) {
|
||||||
|
item.quality += this._getQualityChange(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
_getQualityChange(item) {
|
||||||
if (this._isBackstagePass(item)) {
|
if (this._isBackstagePass(item)) {
|
||||||
this._updateQualityBackstagePass(item);
|
return this._getQualityChangeBackstagePass(item);
|
||||||
} else if (this._isAgedBrie(item)) {
|
} else if (this._isAgedBrie(item)) {
|
||||||
this._updateQualityAgedBrie(item);
|
return this._getQualityChangeAgedBrie(item);
|
||||||
} else if (this._isSulfuras(item)) {
|
} else if (this._isSulfuras(item)) {
|
||||||
|
return this._getQualityChangeSulfuras(item);
|
||||||
} else {
|
} else {
|
||||||
this._updateQualityStandard(item)
|
return this._getQualityChangeStandard(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,34 +46,38 @@ class Shop {
|
|||||||
return item.name.toLowerCase().match(/sulfuras/);
|
return item.name.toLowerCase().match(/sulfuras/);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateQualityStandard(item) {
|
_getQualityChangeStandard(item) {
|
||||||
if (item.sellIn <= 0) {
|
if (item.sellIn <= 0) {
|
||||||
item.quality -= 2;
|
return -2;
|
||||||
} else {
|
} else {
|
||||||
item.quality -= 1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateQualityBackstagePass(item) {
|
_getQualityChangeBackstagePass(item) {
|
||||||
if (item.sellIn <= 0) {
|
if (item.sellIn <= 0) {
|
||||||
item.quality = 0;
|
return -item.quality;
|
||||||
} else if (item.sellIn <= 5) {
|
} else if (item.sellIn <= 5) {
|
||||||
item.quality += 3;
|
return 3;
|
||||||
} else if (item.sellIn <= 10) {
|
} else if (item.sellIn <= 10) {
|
||||||
item.quality += 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
item.quality += 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateQualityAgedBrie(item) {
|
_getQualityChangeAgedBrie(item) {
|
||||||
if (item.sellIn <= 0) {
|
if (item.sellIn <= 0) {
|
||||||
item.quality += 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
item.quality += 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getQualityChangeSulfuras(item) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
_updateItemSellIn(item) {
|
_updateItemSellIn(item) {
|
||||||
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn = item.sellIn - 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user