mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +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
|
class GildedRose
|
||||||
|
|
||||||
# def initialize(items)
|
|
||||||
# @items = items
|
|
||||||
# end
|
|
||||||
|
|
||||||
def self.update_quality(items)
|
def self.update_quality(items)
|
||||||
items.map do |item|
|
items.map do |item|
|
||||||
if !special_item?(item)
|
case
|
||||||
update_normal_quality(item)
|
when !special_item?(item)
|
||||||
item.sell_in -= 1
|
update_normal_quality(item)
|
||||||
elsif item.name.downcase.match /backstage/
|
item.sell_in -= 1
|
||||||
|
when backstage?(item)
|
||||||
update_backstage_quality(item) if item.quality < 50
|
update_backstage_quality(item) if item.quality < 50
|
||||||
item.sell_in -= 1
|
item.sell_in -= 1
|
||||||
elsif item.name.downcase.match /aged brie/
|
when brie?(item)
|
||||||
update_brie_quality(item)
|
update_brie_quality(item)
|
||||||
item.sell_in -= 1
|
item.sell_in -= 1
|
||||||
end
|
end
|
||||||
@ -38,7 +35,6 @@ class GildedRose
|
|||||||
else
|
else
|
||||||
item.quality -= 1 unless item.quality.zero?
|
item.quality -= 1 unless item.quality.zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_brie_quality(item)
|
def self.update_brie_quality(item)
|
||||||
@ -53,9 +49,20 @@ class GildedRose
|
|||||||
!item.name.downcase.match( /sulfuras/).nil?
|
!item.name.downcase.match( /sulfuras/).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.special_item?(item)
|
def self.brie?(item)
|
||||||
( !item.name.downcase.match( /aged brie/).nil? || !item.name.downcase.match(/backstage/).nil? || sulfuras?(item))
|
!item.name.downcase.match( /aged brie/).nil?
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,9 @@ require 'gilded_rose'
|
|||||||
|
|
||||||
describe GildedRose do
|
describe GildedRose do
|
||||||
let(:potato) { Item.new('potato', 15, 2)}
|
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) }
|
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
|
it "does not change the name" do
|
||||||
items = [Item.new("foo", 0, 0)]
|
items = [Item.new("foo", 0, 0)]
|
||||||
GildedRose.update_quality(items)
|
GildedRose.update_quality(items)
|
||||||
@ -189,6 +188,30 @@ let(:sulfarus) { Item.new('Sulfuras, Hand of Ragnaros', 50, 80) }
|
|||||||
|
|
||||||
end
|
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