mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Enhancements and improvements in GildedRose
This commit is contained in:
parent
7d758b5dc0
commit
05be0f3c05
@ -1,3 +1,4 @@
|
|||||||
|
require 'byebug'
|
||||||
class GildedRose
|
class GildedRose
|
||||||
|
|
||||||
def initialize(items)
|
def initialize(items)
|
||||||
@ -6,63 +7,34 @@ class GildedRose
|
|||||||
|
|
||||||
def update_quality()
|
def update_quality()
|
||||||
@items.each do |item|
|
@items.each do |item|
|
||||||
if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert"
|
|
||||||
if item.quality > 0
|
# Decreasing the quality of item
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
if !item.is_aged_brie? && !item.is_backstage_passes? && !item.is_sulfuras? && item.quality > 0
|
||||||
item.quality = item.quality - 1
|
if item.sell_in < 0
|
||||||
end
|
item.quality = item.quality - 4 if item.is_conjured_mana_cake?
|
||||||
|
item.quality = item.quality - 2 if !item.is_conjured_mana_cake?
|
||||||
|
else
|
||||||
|
item.quality = item.quality - 2 if item.is_conjured_mana_cake?
|
||||||
|
item.quality = item.quality - 1 if !item.is_conjured_mana_cake?
|
||||||
end
|
end
|
||||||
else
|
elsif item.quality < 50 && (item.is_backstage_passes? || item.is_aged_brie?)
|
||||||
if item.quality < 50
|
if item.sell_in < 11
|
||||||
|
item.quality = item.quality + 2
|
||||||
|
elsif item.sell_in < 6
|
||||||
|
item.quality = item.quality + 3
|
||||||
|
else
|
||||||
item.quality = item.quality + 1
|
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
|
||||||
|
item.quality = 50 if item.quality > 50
|
||||||
end
|
end
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros"
|
|
||||||
|
if !item.is_sulfuras?
|
||||||
item.sell_in = item.sell_in - 1
|
item.sell_in = item.sell_in - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if item.sell_in < 0
|
if item.sell_in < 0
|
||||||
if item.name != "Aged Brie"
|
item.quality = item.quality - item.quality if item.is_aged_brie? || item.is_backstage_passes?
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Item
|
|
||||||
attr_accessor :name, :sell_in, :quality
|
|
||||||
|
|
||||||
def initialize(name, sell_in, quality)
|
|
||||||
@name = name
|
|
||||||
@sell_in = sell_in
|
|
||||||
@quality = quality
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_s()
|
|
||||||
"#{@name}, #{@sell_in}, #{@quality}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
require "rspec"
|
||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
|
require File.join(File.dirname(__FILE__), 'item')
|
||||||
describe GildedRose do
|
describe GildedRose do
|
||||||
|
|
||||||
describe "#update_quality" do
|
describe "#update_quality" do
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
|
require File.join(File.dirname(__FILE__), 'item')
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class TestUntitled < Test::Unit::TestCase
|
class TestUntitled < Test::Unit::TestCase
|
||||||
|
|||||||
29
ruby/item.rb
Normal file
29
ruby/item.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
class Item
|
||||||
|
attr_accessor :name, :sell_in, :quality
|
||||||
|
|
||||||
|
def initialize(name, sell_in, quality)
|
||||||
|
@name = name
|
||||||
|
@sell_in = sell_in
|
||||||
|
@quality = quality
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_s()
|
||||||
|
"#{@name}, #{@sell_in}, #{@quality}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_aged_brie?
|
||||||
|
name == "Aged Brie"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_backstage_passes?
|
||||||
|
name == "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_sulfuras?
|
||||||
|
name == "Sulfuras, Hand of Ragnaros"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_conjured_mana_cake?
|
||||||
|
name == "Conjured Mana Cake"
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/ruby -w
|
#!/usr/bin/ruby -w
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
require File.join(File.dirname(__FILE__), 'gilded_rose')
|
||||||
|
require File.join(File.dirname(__FILE__), 'item')
|
||||||
|
|
||||||
puts "OMGHAI!"
|
puts "OMGHAI!"
|
||||||
items = [
|
items = [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user