This repository has been archived by the owner on Aug 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cute_as_a_button.rb
106 lines (85 loc) · 1.88 KB
/
cute_as_a_button.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
HOURS_TO_WORK = 8
class Workday
attr_reader :started_at
def initialize(started_at, worktime)
@started_at = started_at
@paused = 0
@working = true
@duration = @worktime = worktime
end
def work
@working = true
end
def pause
@working = false
end
def working?
@working
end
def duration
@duration = end_of_work - Time.now unless @duration.to_i == 0
end
def idle
@paused += 1 unless @duration.to_i == 0
end
def end_of_work
Time.at(@started_at + @worktime + @paused)
end
end
class Shoes::App
def time_as_string(time)
if time.is_a?(Time)
time.strftime("%H:%M")
else
"%02d:%02d" % [
time / (60 * 60),
time / 60 % 60
]
end
end
def start
@workday = Workday.new(Time.now, HOURS_TO_WORK * 3600)
draw_button_stack('pause')
end
def pause
@workday.pause
draw_button_stack('work')
end
def work
@workday.work
draw_button_stack('pause')
end
def draw_button(action)
button(action.capitalize, :width => 70) do
send(action)
end
end
def draw_button_stack(action)
if @button
@button.clear stack do
draw_button(action)
end
else
@button = stack do
draw_button(action)
end
end
end
end
Shoes.app :title => 'Cute As A Button', :width => 160, :height => 110 do
working_since = para "#{ws = 'Started at:'}\n"
go_home_at = para "#{gha = 'Go home at:'}\n"
time_to_go = para "#{ttg = 'Time to go:'}\n"
animate(1) do
if @workday
if @workday.working?
working_since.replace "#{ws}\t#{time_as_string(@workday.started_at)}\n"
time_to_go.replace "#{ttg}\t#{time_as_string(@workday.duration)}\n"
else
@workday.idle
end
go_home_at.replace "#{gha}\t#{time_as_string(@workday.end_of_work)}\n"
end
end
draw_button_stack('start')
end