Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added in modified code for challenge #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 59 additions & 41 deletions update_quality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,66 @@

def update_quality(awards)
awards.each do |award|
if award.name != 'Blue First' && award.name != 'Blue Compare'
if award.quality > 0
if award.name != 'Blue Distinction Plus'
award.quality -= 1
end
end
else
if award.quality < 50
award.quality += 1
if award.name == 'Blue Compare'
if award.expires_in < 11
if award.quality < 50
award.quality += 1
end
end
if award.expires_in < 6
if award.quality < 50
award.quality += 1
end
end
end
end
end
if award.name != 'Blue Distinction Plus'
award.expires_in -= 1
end
if award.expires_in < 0
if award.name != 'Blue First'
if award.name != 'Blue Compare'
if award.quality > 0
if award.name != 'Blue Distinction Plus'
award.quality -= 1
end
end
else
award.quality = award.quality - award.quality
end
else
if award.quality < 50
award.quality += 1
end
rule = reward_rules[award.name] # load rule for award
award.quality += rule[:rate] # Apply basic rate
award.expires_in += rule[:expire_rate] # Apply expiration rate
rule[:modifiers]&.each do |mod|
if mod[:time_left] > award.expires_in # Modifiers sorted by time left and after first available will fit condition, we will skip other
award.quality += mod[:rate] # Apply special quality rate
break # skip rest modifiers
end
end

award.quality = rule[:max_quality] if award.quality > rule[:max_quality] # if quality become greater then max quality, we reset to max value
award.quality = rule[:min_quality] if award.quality < rule[:min_quality] # same as max, just for min value
end
end

def reward_rules
{
'NORMAL ITEM' => {
rate: -1, # Basic quality rate
expire_rate: -1, # Expiration rate
max_quality: 50, # Max posible quality
min_quality: 0, # Min possible quality
modifiers: [ # Special rules depends on time left
{time_left: 0, rate: -1}
]
},
'Blue First' => {
rate: +1,
expire_rate: -1,
max_quality: 50,
min_quality: 0,
modifiers: [
{time_left: 0, rate: +1}
]
},
'Blue Distinction Plus' => {
rate: 0,
expire_rate: 0,
max_quality: 80,
min_quality: 80
},
'Blue Compare' => {
rate: +1,
expire_rate: -1,
max_quality: 50,
min_quality: 0,
modifiers: [
{time_left: 0, rate: -99}, # Nulify quality if it reach 0
{time_left: 5, rate: +2},
{time_left: 10, rate: +1}
]
},
'Blue Star' => {
rate: -2,
expire_rate: -1,
max_quality: 50,
min_quality: 0,
modifiers: [
{time_left: 0, rate: -2}
]
},
}
end
4 changes: 2 additions & 2 deletions update_quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
end

context 'given a Blue Star award' do
before { pending }
# Removed to enable test -- skipped by default
let(:name) { 'Blue Star' }
before { award.expires_in.should == initial_expires_in-1 }

Expand Down Expand Up @@ -234,4 +234,4 @@
specify { expect(awards[1].expires_in).to eq(2) }
end
end
end
end