mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 15:31:27 +00:00
さらば、すべてのSULFURAS
This commit is contained in:
parent
5cbc4ac822
commit
3fe730ddc4
@ -5,28 +5,30 @@ class GildedRose
|
|||||||
AGED_BRIE = "Aged Brie"
|
AGED_BRIE = "Aged Brie"
|
||||||
BACKSTAGE_PASS = "Backstage passes to a TAFKAL80ETC concert"
|
BACKSTAGE_PASS = "Backstage passes to a TAFKAL80ETC concert"
|
||||||
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
SULFURAS = "Sulfuras, Hand of Ragnaros"
|
||||||
|
QUALITY_THRESHOLD = 50
|
||||||
|
|
||||||
def initialize(items)
|
def initialize(items)
|
||||||
@items = items
|
@items = items
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment_item_quality(item)
|
def increment_item_quality(item, num = 1)
|
||||||
item.quality = item.quality + 1
|
item.quality = [item.quality + num, QUALITY_THRESHOLD].min
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_step(item)
|
def first_step(item)
|
||||||
if item.name == AGED_BRIE || item.name == BACKSTAGE_PASS
|
case item.name
|
||||||
return unless item.quality < 50
|
when AGED_BRIE
|
||||||
increment_item_quality(item)
|
increment_item_quality(item)
|
||||||
return if item.name == AGED_BRIE
|
when BACKSTAGE_PASS
|
||||||
if item.sell_in < 11 && item.quality < 50
|
if item.sell_in >= 11
|
||||||
increment_item_quality(item)
|
|
||||||
end
|
|
||||||
if item.sell_in < 6 && item.quality < 50
|
|
||||||
increment_item_quality(item)
|
increment_item_quality(item)
|
||||||
|
elsif (6...11).cover?(item.sell_in)
|
||||||
|
increment_item_quality(item, 2)
|
||||||
|
elsif item.sell_in < 6
|
||||||
|
increment_item_quality(item, 3)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if item.quality > 0 && item.name != SULFURAS
|
if item.quality > 0
|
||||||
item.quality = item.quality - 1
|
item.quality = item.quality - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -34,23 +36,19 @@ class GildedRose
|
|||||||
|
|
||||||
def update_quality()
|
def update_quality()
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
|
return if item.name == SULFURAS
|
||||||
|
|
||||||
first_step(item)
|
first_step(item)
|
||||||
if item.name != SULFURAS
|
item.sell_in = item.sell_in - 1
|
||||||
item.sell_in = item.sell_in - 1
|
|
||||||
end
|
|
||||||
if item.sell_in < 0
|
if item.sell_in < 0
|
||||||
if item.name == AGED_BRIE
|
if item.name == AGED_BRIE
|
||||||
if item.quality < 50
|
increment_item_quality(item)
|
||||||
increment_item_quality(item)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if item.name == BACKSTAGE_PASS
|
if item.name == BACKSTAGE_PASS
|
||||||
item.quality = 0
|
item.quality = 0
|
||||||
else
|
else
|
||||||
if item.quality > 0
|
if item.quality > 0
|
||||||
if item.name != SULFURAS
|
item.quality = item.quality - 1
|
||||||
item.quality = item.quality - 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user