-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathaward.rb
More file actions
77 lines (58 loc) · 1.6 KB
/
award.rb
File metadata and controls
77 lines (58 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Award
attr_accessor :name, :expires_in, :quality
# Award type constants
BLUE_FIRST = 'Blue First'
BLUE_COMPARE = 'Blue Compare'
BLUE_DISTINCTION_PLUS = 'Blue Distinction Plus'
BLUE_STAR = 'Blue Star'
# Quality constraints
MIN_QUALITY = 0
MAX_QUALITY = 50
def initialize(name, expires_in, quality)
@name = name
@expires_in = expires_in
@quality = quality
end
def update_quality
return if @name == BLUE_DISTINCTION_PLUS
adjust_quality
@expires_in -= 1
adjust_quality_for_expiration if @expires_in < 0
end
private
def adjust_quality
case @name
when BLUE_FIRST
increase_quality(1)
when BLUE_COMPARE
increase_quality(quality_increase_for_blue_compare)
when BLUE_STAR
decrease_quality(2)
else
decrease_quality(1)
end
end
def adjust_quality_for_expiration
case @name
when BLUE_FIRST
increase_quality(1) # Gets better with age, even after expiration
when BLUE_COMPARE
@quality = 0 # Drops to zero immediately after expiration
when BLUE_STAR
decrease_quality(2) # Degrades twice as fast = 4 total per day
else
decrease_quality(1) # Normal awards degrade twice as fast = 2 total per day
end
end
def quality_increase_for_blue_compare
return 3 if @expires_in <= 5
return 2 if @expires_in <= 10
1
end
def increase_quality(amount)
@quality = [@quality + amount, MAX_QUALITY].min
end
def decrease_quality(amount)
@quality = [@quality - amount, MIN_QUALITY].max
end
end