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

Solution #80

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP: adds award manager with every condition
dmitryjum committed Apr 25, 2023
commit 11ee8a1cfb293df2ca08ea2e72e4b416f8bfe1cf
46 changes: 42 additions & 4 deletions award_manager.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class AwardManager
attr_accessor :award

def initialise(award)
def initialize(award)
@award = award
end

def update_quality
unless award.name === 'Blue Distinction Plus'
unless award.name == 'Blue Distinction Plus'
case award.name
when 'Blue Compare'
blue_compare
@@ -23,21 +23,59 @@ def update_quality
end

private
# quality score degrades by 1 before the expiration
# quality score degrades by 2 after the expiration
# quality can't be less than 0

def normal_award
if award.expires_in > 0 && award.quality > 0
award.quality -= 1
elsif award.expires_in <= 0 && award.quality > 0
award.quality -= 2
end
end

def blue_compare
award.quality = 0 if award.quality < 0
end

# quality increases by 1 before expiration
# quality increases by 2 on the day of expiration and after
# quality can't be greater than 50

def blue_first
if award.expires_in > 0 && award.quality < 50
award.quality += 1
elsif award.expires_in <= 0 && award.quality < 50
award.quality += 2
end
end

# quality increases by 1 before expiration
# quality increases by 2 when expires_in <= 10
# quality increases by 3 when expires_in <= 5
# quality = 0 when expires_in <= 0

def blue_compare
if award.expires_in > 10
award.quality += 1
elsif award.expires_in <= 10 && award.expires_in > 5
award.quality += 2
elsif award.expires_in <= 5 && award.expires_in > 0
award.quality += 3
else
award.quality = 0
end
end

# quality degrades by 2 before the expiration
# quality degrades by 4 after the expiration

def blue_star
if award.expires_in > 0 && award.quality > 0
award.quality -= 2
elsif award.expires_in <= 0 && award.quality > 0
award.quality -= 4
end

award.quality = 0 if award.quality < 0
end
end