mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
composing methods
This commit is contained in:
parent
c90bc34dc5
commit
154f9dc7ad
@ -1,42 +1,42 @@
|
|||||||
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)
|
||||||
|
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.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
|
end
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
item.quality = item.quality + 1
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert"
|
if item.name == 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
if item.sell_in < 11
|
if item.sell_in < 11
|
||||||
if item.quality < 50
|
item.quality = item.quality + 1 if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if item.sell_in < 6
|
if item.sell_in < 6
|
||||||
if item.quality < 50
|
item.quality = item.quality + 1 if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
item.sell_in = item.sell_in - 1 if item.name != 'Sulfuras, Hand of Ragnaros'
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
|
||||||
item.sell_in = item.sell_in - 1
|
|
||||||
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
|
end
|
||||||
@ -44,10 +44,7 @@ class GildedRose
|
|||||||
item.quality = item.quality - item.quality
|
item.quality = item.quality - item.quality
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if item.quality < 50
|
item.quality = item.quality + 1 if item.quality < 50
|
||||||
item.quality = item.quality + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user