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) 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" update_item_quality(item)
if item.quality > 0 end
if item.name != "Sulfuras, Hand of Ragnaros" end
item.quality = item.quality - 1
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 end
else end
if item.quality < 50 else
item.quality = item.quality + 1 if item.quality < 50
if item.name == "Backstage passes to a TAFKAL80ETC concert" item.quality = item.quality + 1
if item.sell_in < 11 if item.name == 'Backstage passes to a TAFKAL80ETC concert'
if item.quality < 50 if item.sell_in < 11
item.quality = item.quality + 1 item.quality = item.quality + 1 if item.quality < 50
end end
end if item.sell_in < 6
if item.sell_in < 6 item.quality = item.quality + 1 if item.quality < 50
if item.quality < 50
item.quality = item.quality + 1
end
end
end end
end end
end end
if item.name != "Sulfuras, Hand of Ragnaros" end
item.sell_in = item.sell_in - 1 item.sell_in = item.sell_in - 1 if item.name != 'Sulfuras, Hand of Ragnaros'
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 passes to a TAFKAL80ETC concert" if item.quality > 0
if item.quality > 0 if item.name != 'Sulfuras, Hand of Ragnaros'
if item.name != "Sulfuras, Hand of Ragnaros" item.quality = item.quality - 1
item.quality = item.quality - 1
end
end end
else
item.quality = item.quality - item.quality
end end
else else
if item.quality < 50 item.quality = item.quality - item.quality
item.quality = item.quality + 1
end
end end
else
item.quality = item.quality + 1 if item.quality < 50
end end
end end
end end
@ -62,7 +59,7 @@ class Item
@quality = quality @quality = quality
end end
def to_s() def to_s
"#{@name}, #{@sell_in}, #{@quality}" "#{@name}, #{@sell_in}, #{@quality}"
end end
end end