Permalink
Browse files

Refactor to implement Factory strategy

  • Loading branch information...
francho committed Jun 10, 2016
1 parent 4537b82 commit 4355372f1b51caae3bd85b3980d630f7594e5331
Showing with 9 additions and 14 deletions.
  1. +3 −1 gilded_rose.rb
  2. +6 −13 lib/item_updater.rb
View
@@ -2,7 +2,9 @@
def update_quality(items)
items.each do |item|
ItemUpdater.update item
updater = ItemUpdater.for item
updater.update_sell_in
updater.update_quality
end
end
View
@@ -4,21 +4,15 @@
require 'sulfuras_updater'
class ItemUpdater
def self.update(item)
updater = if backstage? item
BackstageUpdater.new(item)
elsif aged_brie? item
AgedBrieUpdater.new(item)
elsif sulfuras? item
SulfurasUpdater.new(item)
else
BaseUpdater.new(item)
end
def self.for(item)
return BackstageUpdater.new(item) if backstage? item
return AgedBrieUpdater.new(item) if aged_brie? item
return SulfurasUpdater.new(item) if sulfuras? item
updater.update_sell_in
updater.update_quality
return BaseUpdater.new(item)
end
private
def self.aged_brie?(item)
item.name.eql? 'Aged Brie'
end
@@ -30,5 +24,4 @@ def self.backstage?(item)
def self.sulfuras?(item)
item.name.eql? 'Sulfuras, Hand of Ragnaros'
end
end

0 comments on commit 4355372

Please sign in to comment.