forked from mdx-dev/platform-code-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
award.rb
114 lines (100 loc) · 2.04 KB
/
award.rb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class Award
attr_reader :name, :expires_in, :quality
BLUE_FIRST = "Blue First"
BLUE_COMPARE = "Blue Compare"
BLUE_DISTINCTION_PLUS = "Blue Distinction Plus"
BLUE_STAR = "Blue Star"
NORMAL = "Normal"
def initialize(name, expires_in, quality)
@name = name
@expires_in = expires_in
@quality = quality
set_type
end
def update_quality
case @type
when BLUE_FIRST
blue_first_update()
when BLUE_COMPARE
blue_compare_update()
when BLUE_DISTINCTION_PLUS
blue_distinction_plus_update()
when BLUE_STAR
blue_star_update()
else
normal_update()
end
end
private
def set_type
case @name
when BLUE_FIRST
@type = BLUE_FIRST
when BLUE_COMPARE
@type = BLUE_COMPARE
when BLUE_DISTINCTION_PLUS
@type = BLUE_DISTINCTION_PLUS
when BLUE_STAR
@type = BLUE_STAR
else
@type = NORMAL
end
end
def update_expiration
@expires_in -= 1
end
def blue_first_update
if @quality < 50
if @expires_in > 0
@quality += 1
else
if @quality >= 48
@quality = 50
else
@quality += 2
end
end
end
update_expiration()
end
def blue_compare_update
if @expires_in <= 0
@quality = 0
elsif @quality < 50
if @expires_in <= 5
@quality += 3
elsif @expires_in <= 10
@quality += 2
else
@quality += 1
end
end
update_expiration()
end
def base_award_update(multiplier=1)
if @quality > 0
if @expires_in > 0
@quality -= (1 * multiplier)
else
if @quality <= (2 * multiplier)
@quality = 0
else
@quality -= (2 * multiplier)
end
end
end
end
def blue_distinction_plus_update
if @quality < 80
@quality += 1
end
end
def blue_star_update
base_award_update(2)
update_expiration()
end
def normal_update
base_award_update()
update_expiration()
end
end