Skip to content

Commit

Permalink
Here's my solution to the kata.
Browse files Browse the repository at this point in the history
  • Loading branch information
JEG2 committed Dec 8, 2011
1 parent b1e1d3a commit 28eae69
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 44 deletions.
118 changes: 75 additions & 43 deletions gilded_rose.rb
@@ -1,51 +1,83 @@
def update_quality(items) module Aging
items.each do |item| def age
if item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert' update_quality
if item.quality > 0 update_sell_in
if item.name != 'Sulfuras, Hand of Ragnaros' end
item.quality -= 1
end def update_sell_in
end self.sell_in -= 1
else end
if item.quality < 50
item.quality += 1 def update_quality
if item.name == 'Backstage passes to a TAFKAL80ETC concert' reduce_quality(sell_in <= 0 ? 2 : 1)
if item.sell_in < 11 end
if item.quality < 50
item.quality += 1 def reduce_quality(amount)
end self.quality = [quality - amount, 0].max
end end
if item.sell_in < 6
if item.quality < 50 def increase_quality(amount)
item.quality += 1 self.quality = [quality + amount, 50].min
end end
end end
end
end module BetterWithAge
end def update_quality
if item.name != 'Sulfuras, Hand of Ragnaros' increase_quality(sell_in <= 0 ? 2 : 1)
item.sell_in -= 1 end
end end
if item.sell_in < 0
if item.name != "Aged Brie" module Popular
if item.name != 'Backstage passes to a TAFKAL80ETC concert' def update_quality
if item.quality > 0 increase_quality(
if item.name != 'Sulfuras, Hand of Ragnaros' case sell_in
item.quality -= 1 when -Float::INFINITY..0 then -quality
end when 1..5 then 3
end when 6..10 then 2
else else 1
item.quality = item.quality - item.quality
end
else
if item.quality < 50
item.quality += 1
end
end end
)
end
end

module Legendary
def update_sell_in
# do nothing: never has to be sold
end

def update_quality
# do nothing: does not degrade
end
end

module Conjured
def update_quality
2.times do
super
end end
end end
end end


def prepare_for_aging(item)
unless item.respond_to? :age
item.extend(Aging)
type = case item.name
when /Aged Brie/i then BetterWithAge
when /Backstage pass/i then Popular
when /Sulfuras/i then Legendary
when /Conjured/i then Conjured
end
item.extend(type) if type
end
item
end

def update_quality(items)
items.each do |item|
prepare_for_aging(item).age
end
end

# DO NOT CHANGE THINGS BELOW ----------------------------------------- # DO NOT CHANGE THINGS BELOW -----------------------------------------


Item = Struct.new(:name, :sell_in, :quality) Item = Struct.new(:name, :sell_in, :quality)
Expand Down
1 change: 0 additions & 1 deletion gilded_rose_spec.rb
Expand Up @@ -169,7 +169,6 @@
end end


context "conjured item" do context "conjured item" do
before { pending }
Given(:name) { "Conjured Mana Cake" } Given(:name) { "Conjured Mana Cake" }


context "before the sell date" do context "before the sell date" do
Expand Down

0 comments on commit 28eae69

Please sign in to comment.