Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: extract method #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 49 additions & 37 deletions ruby/gilded_rose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,62 @@ def initialize(items)

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
end
else
if item.name == "Aged Brie"
handle_aged_brie(item)
end

if item.name == "Backstage passes to a TAFKAL80ETC concert"
handle_backstage(item)
end

if item.name == "foo"
handle_normal(item)
end
end
end

def handle_aged_brie(item)
if item.quality < 50
item.quality = item.quality + 1
end
item.sell_in = item.sell_in - 1
if item.sell_in < 0
if item.quality < 50
item.quality = item.quality + 1
end
end
end

def handle_backstage(item)
if item.quality < 50
item.quality = item.quality + 1
if item.sell_in < 11
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
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
if item.quality < 50
item.quality = item.quality + 1
end
if item.sell_in < 6
if item.quality < 50
item.quality = item.quality + 1
end
end
end
item.sell_in = item.sell_in - 1
if item.sell_in < 0
item.quality = item.quality - item.quality
end
end

def handle_normal(item)
if item.quality > 0
item.quality = item.quality - 1
end
item.sell_in = item.sell_in - 1
if item.sell_in < 0
if item.quality > 0
item.quality = item.quality - 1
end
end
end
end

Expand Down