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