Created
December 9, 2011 03:36
-
-
Save thirtysixthspan/1450033 to your computer and use it in GitHub Desktop.
The Gilded Rose Code Kata - a 'solution'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_quality(items) | |
rules = { "Conjured" => { ds:-1, mq:50, dq:[ -4, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 ]}, | |
"Sulfuras" => { ds: 0, mq:80, dq:[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]}, | |
"Aged Brie" => { ds:-1, mq:50, dq:[ +2, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1, +1 ]}, | |
"Backstage" => { ds:-1, mq:50, dq:[-50, +3, +3, +3, +3, +3, +2, +2, +2, +2, +2, +1 ]}, | |
"." => { ds:-1, mq:50, dq:[ -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 ]}} | |
items.each do |item| | |
rules.each do |key,rule| | |
if item.name=~/#{key}/ | |
item.quality += rule[:dq][ [0, item.sell_in, 11].sort[1] ] | |
item.quality = [0, item.quality, rule[:mq]].sort[1] | |
item.sell_in += rule[:ds] | |
break | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment