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

Stanley Platform-code-test #75

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
7 changes: 7 additions & 0 deletions contraints/exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Exception
def update_quality(award)
##if name is blue distinciton plus, quality should be 80 and should not expire
award.quality = 80 if award.name == 'Blue Distinction Plus'
award.expires_in -= 1 if award.name != 'Blue Distinction Plus'
end
end
7 changes: 7 additions & 0 deletions contraints/value_constraint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ValueConstraint
def update_quality(award)
#values should be between 0 and 50
award.quality = 0 if award.quality < 0
award.quality = 50 if award.quality > 50 && award.name != 'Blue Distinction Plus'
end
end
69 changes: 27 additions & 42 deletions update_quality.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
require 'award'
require 'updaters/blue_first_up'
require 'updaters/blue_comp_up'
require 'updaters/blue_star_up'
require 'updaters/blue_dist_plus_up'
require 'contraints/value_constraint'
require 'contraints/exception'

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

case award.name
#Blue Compare Award
when 'Blue Compare'
BlueCompare.new.update_quality(award)

when 'Blue Star'
BlueStar.new.update_quality(award)

# Blue First Award
when 'Blue First'
BlueFirst.new.update_quality(award)

# Blue Distinction Plus Award
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
end
BlueDistinctionPlus.new.update_quality(award)
end

# Sets qaulity to range 0-50
ValueConstraint.new.update_quality(award)
# Ecxeption for Blue Distinction Plus quaility decreasement
Exception.new.update_quality(award)
end
end
end
1 change: 0 additions & 1 deletion update_quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
end

context 'given a Blue Star award' do
before { pending }
let(:name) { 'Blue Star' }
before { award.expires_in.should == initial_expires_in-1 }

Expand Down
15 changes: 15 additions & 0 deletions updaters/blue_comp_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BlueCompare
def update_quality(award)
#increase quality as expires_in increases
award.quality += 1
# increases the quality by 1 more if the expiration date is less than or equal to 10 days
award.quality += 1 if award.expires_in <= 10
#increases the quality by 1 more if the expiration date is less than or equal to 5 days
award.quality += 1 if award.expires_in <= 5
#sets the quality to 0 if the expiration date is <= 0
award.quality = 0 if award.expires_in <= 0

end


end
7 changes: 7 additions & 0 deletions updaters/blue_dist_plus_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BlueDistinctionPlus
def update_quality(award)
award.quality -= 1
award.quality -= 1 if award.expires_in <= 0
end

end
9 changes: 9 additions & 0 deletions updaters/blue_first_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class BlueFirst
def update_quality(award)
#increase quality as expires_in increases
award.quality += 1
award.quality += 1 if award.expires_in <= 0
end

end

7 changes: 7 additions & 0 deletions updaters/blue_star_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BlueStar
def update_quality(award)
##if name is blue star, quality should be lost twice as fast
award.quality -= 2
award.quality -= 2 if award.expires_in <= 0
end
end