composing methods

This commit is contained in:
davidraj 2022-10-10 16:20:32 +01:00
parent c90bc34dc5
commit 154f9dc7ad

View File

@ -1,53 +1,50 @@
class GildedRose
# frozen_string_literal: true
class GildedRose
def initialize(items)
@items = items
end
def update_quality()
def update_quality
@items.each do |item|
if item.name != "Aged Brie" and 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
update_item_quality(item)
end
end
def update_item_quality(item)
if (item.name != 'Aged Brie') && (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
else
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
else
if item.quality < 50
item.quality = item.quality + 1
if item.name == 'Backstage passes to a TAFKAL80ETC concert'
if item.sell_in < 11
item.quality = item.quality + 1 if item.quality < 50
end
if item.sell_in < 6
item.quality = item.quality + 1 if item.quality < 50
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
item.sell_in = item.sell_in - 1 if item.name != 'Sulfuras, Hand of Ragnaros'
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
else
item.quality = item.quality - item.quality
end
else
if item.quality < 50
item.quality = item.quality + 1
end
item.quality = item.quality - item.quality
end
else
item.quality = item.quality + 1 if item.quality < 50
end
end
end
@ -62,7 +59,7 @@ class Item
@quality = quality
end
def to_s()
def to_s
"#{@name}, #{@sell_in}, #{@quality}"
end
end