-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_process.rb
More file actions
99 lines (86 loc) · 2.15 KB
/
Copy pathtimer_process.rb
File metadata and controls
99 lines (86 loc) · 2.15 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class TimerProcess
attr_reader :name, :modifier, :colour
def initialize(process_csv)
header = process_csv.shift
@name = header[0]
@modifier = header[1]
@colour = case(header[2])
when 'RED'
:red
when 'GRN'
:green
when 'BLU'
:blue
when 'YEL'
:yellow
when 'TEA'
:teal
when 'PUR'
:purple
when 'WHT'
:white
else
:red
end
@steps = []
process_csv.each do |step_data|
backlight = :off
case step_data[4].upcase
when "Y"
backlight = :on
when "H"
backlight = :half
end
@steps.push TimerProcessStep.new(self, step_data[1], step_data[0], step_data[2].to_i, step_data[3].upcase == "Y" ? true : false, backlight)
end
end
def [](idx)
@steps[idx]
end
def each_step
@steps.each do |step|
yield step
end
end
def steps
@steps
end
end
class TimerProcessStep
attr_reader :process, :short_name, :long_name, :tweakable, :backlight, :phrases
def initialize(process, short_name, long_name, seconds, tweakable, backlight)
@process = process
@short_name = short_name
@long_name = long_name
@seconds = seconds
@tweakable = tweakable
@backlight = backlight
setup_phrases
end
def setup_phrases
@phrases = Hash.new
@phrases[:ready_to_start] = "Ready to start #{@long_name.downcase} for #{secs_to_ms_words(@seconds)}."
@phrases[:time_left] = "%s left"
@phrases[:light_safe] = "Paper is now light safe."
@phrases[:aborted] = "#{@long_name.downcase} aborted."
@phrases[:complete] = "#{@long_name.downcase} complete."
@phrases[:process_starting] = "Starting process #{@process.name}."
@phrases[:process_complete] = "#{@process.name} process complete."
end
def run
start_time = Time.now
while(Time.now - start_time < @seconds) do
secs_elapsed = (Time.now - start_time).to_i
secs_left = @seconds - secs_elapsed
yield secs_left
sleep 1
end
end
def seconds=(secs)
@seconds = secs
setup_phrases
end
def seconds
@seconds
end
end