mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
created boolean methods for brie and backstage, implemented them in a case statement
This commit is contained in:
parent
e2673f0734
commit
24ebe0b7dd
@ -1,18 +1,15 @@
|
||||
class GildedRose
|
||||
|
||||
# def initialize(items)
|
||||
# @items = items
|
||||
# end
|
||||
|
||||
def self.update_quality(items)
|
||||
items.map do |item|
|
||||
if !special_item?(item)
|
||||
update_normal_quality(item)
|
||||
item.sell_in -= 1
|
||||
elsif item.name.downcase.match /backstage/
|
||||
case
|
||||
when !special_item?(item)
|
||||
update_normal_quality(item)
|
||||
item.sell_in -= 1
|
||||
when backstage?(item)
|
||||
update_backstage_quality(item) if item.quality < 50
|
||||
item.sell_in -= 1
|
||||
elsif item.name.downcase.match /aged brie/
|
||||
when brie?(item)
|
||||
update_brie_quality(item)
|
||||
item.sell_in -= 1
|
||||
end
|
||||
@ -38,7 +35,6 @@ class GildedRose
|
||||
else
|
||||
item.quality -= 1 unless item.quality.zero?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.update_brie_quality(item)
|
||||
@ -53,9 +49,20 @@ class GildedRose
|
||||
!item.name.downcase.match( /sulfuras/).nil?
|
||||
end
|
||||
|
||||
def self.special_item?(item)
|
||||
( !item.name.downcase.match( /aged brie/).nil? || !item.name.downcase.match(/backstage/).nil? || sulfuras?(item))
|
||||
def self.brie?(item)
|
||||
!item.name.downcase.match( /aged brie/).nil?
|
||||
end
|
||||
|
||||
def self.backstage?(item)
|
||||
!item.name.downcase.match(/backstage/).nil?
|
||||
end
|
||||
|
||||
def self.special_item?(item)
|
||||
( brie?(item) || backstage?(item) || sulfuras?(item))
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -2,10 +2,9 @@ require 'gilded_rose'
|
||||
|
||||
describe GildedRose do
|
||||
let(:potato) { Item.new('potato', 15, 2)}
|
||||
#let(:grain) {instance_double("item", name: "potato", :quality => 5)}
|
||||
let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
||||
|
||||
describe "#update_quality" do
|
||||
describe "feature tests" do
|
||||
it "does not change the name" do
|
||||
items = [Item.new("foo", 0, 0)]
|
||||
GildedRose.update_quality(items)
|
||||
@ -188,6 +187,30 @@ let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe '#brie?' do
|
||||
it 'returns true on a brie item' do
|
||||
brie_double = double :brie, name: 'Aged Brie', sell_in: 50, quality: 80
|
||||
expect(GildedRose.brie?(brie_double)).to eq true
|
||||
end
|
||||
|
||||
it 'returns false on a non brie item' do
|
||||
item_double = double :item, name: "potato", sell_in: 1, quality: 0
|
||||
expect(GildedRose.sulfuras?(item_double)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe '#backstage?' do
|
||||
it 'returns true on a backstage item' do
|
||||
backstage_double = double :item, name: "Backstage passes to a TAFKAL80ETC concert"
|
||||
expect(GildedRose.backstage?(backstage_double)).to eq true
|
||||
end
|
||||
|
||||
it 'returns false on a non brie item' do
|
||||
item_double = double :item, name: "potato", sell_in: 1, quality: 0
|
||||
expect(GildedRose.backstage?(item_double)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user