mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Extract min quality checks
This commit is contained in:
parent
8038e6fb07
commit
9eb17f67da
@ -2,6 +2,7 @@ class Shop {
|
|||||||
constructor(items = []) {
|
constructor(items = []) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.MAX_QUALITY = 50;
|
this.MAX_QUALITY = 50;
|
||||||
|
this.MIN_QUALITY = 0;
|
||||||
}
|
}
|
||||||
updateQuality() {
|
updateQuality() {
|
||||||
for (var i = 0; i < this.items.length; i++) {
|
for (var i = 0; i < this.items.length; i++) {
|
||||||
@ -12,10 +13,8 @@ class Shop {
|
|||||||
|
|
||||||
_updateItemQuality(item) {
|
_updateItemQuality(item) {
|
||||||
if (item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert') {
|
if (item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if (item.quality > 0) {
|
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
item.quality = item.quality - 1;
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
@ -32,10 +31,8 @@ class Shop {
|
|||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
if (item.name != 'Aged Brie') {
|
if (item.name != 'Aged Brie') {
|
||||||
if (item.name != 'Backstage passes to a TAFKAL80ETC concert') {
|
if (item.name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if (item.quality > 0) {
|
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
if (item.name != 'Sulfuras, Hand of Ragnaros') {
|
item.quality = item.quality - 1;
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
item.quality = item.quality - item.quality;
|
item.quality = item.quality - item.quality;
|
||||||
@ -45,6 +42,7 @@ class Shop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._checkMaxQuality(item);
|
this._checkMaxQuality(item);
|
||||||
|
this._checkMinQuality(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateSellIn(item) {
|
_updateSellIn(item) {
|
||||||
@ -58,6 +56,12 @@ class Shop {
|
|||||||
item.quality = this.MAX_QUALITY;
|
item.quality = this.MAX_QUALITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_checkMinQuality(item) {
|
||||||
|
if (item.quality < this.MIN_QUALITY) {
|
||||||
|
item.quality = this.MIN_QUALITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Shop
|
Shop
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user