Skip to content

Instantly share code, notes, and snippets.

@thirtysixthspan
Created December 9, 2011 03:36
Show Gist options
  • Save thirtysixthspan/1450033 to your computer and use it in GitHub Desktop.
Save thirtysixthspan/1450033 to your computer and use it in GitHub Desktop.
The Gilded Rose Code Kata - a 'solution'
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