mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 00:11:35 +00:00
Fix ruby version
This commit is contained in:
parent
0f2437eeeb
commit
a95750265b
1
ruby/.ruby-version
Normal file
1
ruby/.ruby-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
2.5.7
|
||||||
@ -1,54 +1,48 @@
|
|||||||
class GildedRose
|
class GildedRose
|
||||||
|
|
||||||
def initialize(items)
|
def initialize(items)
|
||||||
@items = items
|
@items = items
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_quality()
|
def update_quality
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
next if item.name == 'Sulfuras, Hand of Ragnaros'
|
||||||
if item.quality > 0
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
item.sell_in -= 1
|
||||||
item.quality = item.quality - 1
|
|
||||||
end
|
quality_change = case item.name
|
||||||
|
when 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
|
if item.sell_in.negative?
|
||||||
|
item.quality = 0
|
||||||
|
next
|
||||||
end
|
end
|
||||||
else
|
|
||||||
if item.quality < 50
|
if item.sell_in >= 10
|
||||||
item.quality = item.quality + 1
|
1
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
elsif item.sell_in >= 5
|
||||||
if item.sell_in < 11
|
2
|
||||||
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
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
|
||||||
item.sell_in = item.sell_in - 1
|
|
||||||
end
|
|
||||||
if item.sell_in < 0
|
|
||||||
if item.name != "Aged Brie"
|
|
||||||
if item.name != "Backstage passes to a TAFKAL80ETC concert"
|
|
||||||
if item.quality > 0
|
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
|
||||||
item.quality = item.quality - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
item.quality = item.quality - item.quality
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
3
|
||||||
item.quality = item.quality + 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
when 'Conjured Mana Cake'
|
||||||
|
item.sell_in < 0 ? 4 : 2
|
||||||
|
else
|
||||||
|
quality_degradation = item.sell_in < 0 ? 2 : 1
|
||||||
|
|
||||||
|
quality_degradation *= 2 if item.name.start_with?('Conjured')
|
||||||
|
|
||||||
|
quality_degradation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
new_quality = if [
|
||||||
|
'Aged Brie',
|
||||||
|
'Backstage passes to a TAFKAL80ETC concert',
|
||||||
|
].include?(item.name)
|
||||||
|
item.quality + quality_change
|
||||||
|
else
|
||||||
|
item.quality - quality_change
|
||||||
|
end
|
||||||
|
|
||||||
|
item.quality = [[new_quality, 50].min, 0].max
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user