最初の一歩

This commit is contained in:
degwinthegreat 2021-05-14 19:40:17 +09:00
parent 471d1d7966
commit 910360c631

View File

@ -1,42 +1,50 @@
# frozen_string_literal: true
class GildedRose class GildedRose
AGED_BRIE = "Aged Brie"
BACKSTAGE_PASS = "Backstage passes to a TAFKAL80ETC concert"
SULFURAS = "Sulfuras, Hand of Ragnaros"
def initialize(items) def initialize(items)
@items = items @items = items
end end
def update_quality() def increment_item_quality(item)
@items.each do |item| item.quality = item.quality + 1
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert" end
if item.quality > 0
if item.name != "Sulfuras, Hand of Ragnaros" def first_step(item)
item.quality = item.quality - 1 if item.name == AGED_BRIE || item.name == BACKSTAGE_PASS
if item.quality < 50
increment_item_quality(item)
if item.name == BACKSTAGE_PASS
if item.sell_in < 11 && item.quality < 50
increment_item_quality(item)
end end
end if item.sell_in < 6 && item.quality < 50
else increment_item_quality(item)
if item.quality < 50
item.quality = item.quality + 1
if item.name == "Backstage passes to a TAFKAL80ETC concert"
if item.sell_in < 11
if item.quality < 50
item.quality = item.quality + 1
end
end
if item.sell_in < 6
if item.quality < 50
item.quality = item.quality + 1
end
end
end end
end end
end end
if item.name != "Sulfuras, Hand of Ragnaros" else
if item.quality > 0 && item.name != SULFURAS
item.quality = item.quality - 1
end
end
end
def update_quality()
@items.each do |item|
first_step(item)
if item.name != SULFURAS
item.sell_in = item.sell_in - 1 item.sell_in = item.sell_in - 1
end end
if item.sell_in < 0 if item.sell_in < 0
if item.name != "Aged Brie" if item.name != AGED_BRIE
if item.name != "Backstage passes to a TAFKAL80ETC concert" if item.name != BACKSTAGE_PASS
if item.quality > 0 if item.quality > 0
if item.name != "Sulfuras, Hand of Ragnaros" if item.name != SULFURAS
item.quality = item.quality - 1 item.quality = item.quality - 1
end end
end end
@ -45,7 +53,7 @@ class GildedRose
end end
else else
if item.quality < 50 if item.quality < 50
item.quality = item.quality + 1 increment_item_quality(item)
end end
end end
end end