domodoro 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +21 -6
- data/assets/{stop.wav → break.wav} +0 -0
- data/assets/home.wav +0 -0
- data/assets/lunch.wav +0 -0
- data/assets/{start.wav → work.wav} +0 -0
- data/lib/domodoro.rb +2 -0
- data/lib/domodoro/channel.rb +8 -38
- data/lib/domodoro/client.rb +73 -34
- data/lib/domodoro/config.rb +32 -1
- data/lib/domodoro/schedule.rb +82 -0
- data/lib/domodoro/server.rb +20 -4
- data/lib/domodoro/timepoint.rb +80 -0
- data/lib/domodoro/version.rb +1 -1
- data/test/domodoro/channel_test.rb +23 -108
- data/test/domodoro/client_test.rb +65 -129
- data/test/domodoro/config_test.rb +2 -2
- data/test/domodoro/schedule_test.rb +108 -0
- data/test/domodoro/server_test.rb +39 -9
- data/test/domodoro/timepoint_test.rb +105 -0
- metadata +102 -68
@@ -0,0 +1,80 @@
|
|
1
|
+
module Domodoro
|
2
|
+
class Timepoint
|
3
|
+
attr_reader :hour, :min
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
case args.first
|
7
|
+
when String
|
8
|
+
@hour, @min = args.first.split(':').map(&:to_i)
|
9
|
+
when Fixnum
|
10
|
+
@hour, @min = args.first, args.last
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def +(minutes)
|
15
|
+
hours_to_advance = ((@min + minutes) / 60).to_i
|
16
|
+
|
17
|
+
h = @hour + hours_to_advance
|
18
|
+
m = (@min + minutes) % 60
|
19
|
+
|
20
|
+
Timepoint.new("#{h}:#{m}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def after?(timepoint)
|
24
|
+
if @hour > timepoint.hour
|
25
|
+
true
|
26
|
+
elsif @hour == timepoint.hour
|
27
|
+
@min >= timepoint.min
|
28
|
+
else
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def before?(timepoint)
|
34
|
+
if @hour < timepoint.hour
|
35
|
+
true
|
36
|
+
elsif @hour == timepoint.hour
|
37
|
+
@min < timepoint.min
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def ==(timepoint)
|
44
|
+
case timepoint
|
45
|
+
when String
|
46
|
+
Timepoint.new(timepoint) == self
|
47
|
+
when Timepoint
|
48
|
+
@hour == timepoint.hour && @min == timepoint.min
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
[@hour, @min].map(&:to_s).map do |number|
|
54
|
+
number.rjust(2, '0')
|
55
|
+
end.join(':')
|
56
|
+
end
|
57
|
+
|
58
|
+
def left_until(timestamp)
|
59
|
+
secs = 59 - Time.now.sec
|
60
|
+
hours = timestamp.hour - @hour
|
61
|
+
|
62
|
+
if timestamp.hour == @hour
|
63
|
+
remaining_minutes = (timestamp.min - @min - 1).to_s.rjust(2, '0')
|
64
|
+
return "00:#{remaining_minutes}:#{secs.to_s.rjust(2, '0')}"
|
65
|
+
end
|
66
|
+
|
67
|
+
if timestamp.min < @min
|
68
|
+
hours -= 1
|
69
|
+
end
|
70
|
+
|
71
|
+
mins = ((timestamp.min - @min) % 60) - 1
|
72
|
+
|
73
|
+
h = hours.to_s.rjust(2, '0')
|
74
|
+
m = mins.to_s.rjust(2, '0')
|
75
|
+
s = secs.to_s.rjust(2, '0')
|
76
|
+
|
77
|
+
"#{h}:#{m}:#{s}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/domodoro/version.rb
CHANGED
@@ -11,123 +11,38 @@ module Domodoro
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'broadcast' do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@channel.expects(:morning).with(25).once
|
21
|
-
@channel.expects(:morning).with(30).once
|
22
|
-
@channel.expects(:morning).with(35).never
|
23
|
-
|
24
|
-
min = 0
|
25
|
-
(7..13).each do |hour|
|
26
|
-
min += 5
|
27
|
-
@channel.broadcast(hour, min)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'in the afternoon' do
|
33
|
-
it 'broadcasts from 13:20 on' do
|
34
|
-
@channel.expects(:afternoon).with(5).never
|
35
|
-
@channel.expects(:afternoon).with(10).never
|
36
|
-
@channel.expects(:afternoon).with(15).never
|
37
|
-
@channel.expects(:afternoon).with(20).once
|
38
|
-
@channel.expects(:afternoon).with(25).once
|
39
|
-
@channel.expects(:afternoon).with(30).once
|
40
|
-
@channel.expects(:afternoon).with(35).once
|
41
|
-
|
42
|
-
min = 0
|
43
|
-
(13..19).each do |hour|
|
44
|
-
min += 5
|
45
|
-
@channel.broadcast(hour, min)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'does not broadcast during lunch time' do
|
51
|
-
%w(morning afternoon).each do |timespan|
|
52
|
-
@channel.expects(timespan).with(5).never
|
53
|
-
end
|
54
|
-
|
55
|
-
(0..19).each do |min|
|
56
|
-
@channel.broadcast(13, min)
|
57
|
-
end
|
14
|
+
before do
|
15
|
+
@schedule = Schedule.new
|
16
|
+
@schedule.instance_variable_set(:@times, {
|
17
|
+
'08:30' => :start,
|
18
|
+
'09:00' => :stop
|
19
|
+
})
|
58
20
|
end
|
59
|
-
end
|
60
21
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
22
|
+
describe 'if theres an action for the timestamp' do
|
23
|
+
it 'broadcasts it' do
|
24
|
+
@channel.expects(:<<).with(
|
25
|
+
:current_action => ["08:30", :start],
|
26
|
+
:next_action => ["09:00", :stop]
|
27
|
+
)
|
28
|
+
@channel.expects(:<<).with(
|
29
|
+
:current_action => ["09:00", :stop],
|
30
|
+
:next_action => nil
|
31
|
+
)
|
67
32
|
|
68
|
-
|
69
|
-
@channel.
|
70
|
-
@channel.morning 30
|
33
|
+
@channel.broadcast("08:30", @schedule)
|
34
|
+
@channel.broadcast("09:00", @schedule)
|
71
35
|
end
|
72
36
|
end
|
73
37
|
|
74
|
-
describe '
|
75
|
-
it '
|
76
|
-
@channel.expects(:<<).
|
77
|
-
@channel.morning 25
|
78
|
-
end
|
38
|
+
describe 'otherwise' do
|
39
|
+
it 'does not' do
|
40
|
+
@channel.expects(:<<).never
|
79
41
|
|
80
|
-
|
81
|
-
@channel.
|
82
|
-
@channel.morning 55
|
42
|
+
@channel.broadcast("07:30", @schedule)
|
43
|
+
@channel.broadcast("08:31", @schedule)
|
83
44
|
end
|
84
45
|
end
|
85
|
-
|
86
|
-
it 'does not broadcast anything at other times' do
|
87
|
-
@channel.expects(:<<).never
|
88
|
-
|
89
|
-
@channel.morning 5
|
90
|
-
@channel.morning 10
|
91
|
-
@channel.morning 20
|
92
|
-
@channel.morning 40
|
93
|
-
@channel.morning 50
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe '#afternoon' do
|
98
|
-
describe 'pomodoro starts' do
|
99
|
-
it 'broadcasts a :start message when the time is XX:20' do
|
100
|
-
@channel.expects(:<<).with(:start)
|
101
|
-
@channel.afternoon 20
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'broadcasts a :start message when the time is XX:50' do
|
105
|
-
@channel.expects(:<<).with(:start)
|
106
|
-
@channel.afternoon 50
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe 'pomodoro stops' do
|
111
|
-
it 'broadcasts a :stop message when the time is XX:45' do
|
112
|
-
@channel.expects(:<<).with(:stop)
|
113
|
-
@channel.afternoon 45
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'broadcasts a :stop message when the time is XX:15' do
|
117
|
-
@channel.expects(:<<).with(:stop)
|
118
|
-
@channel.afternoon 15
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'does not broadcast anything at other times' do
|
123
|
-
@channel.expects(:<<).never
|
124
|
-
|
125
|
-
@channel.afternoon 5
|
126
|
-
@channel.afternoon 10
|
127
|
-
@channel.afternoon 25
|
128
|
-
@channel.afternoon 40
|
129
|
-
@channel.afternoon 55
|
130
|
-
end
|
131
46
|
end
|
132
47
|
end
|
133
48
|
end
|
@@ -1,160 +1,96 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
module ExampleServer
|
3
|
+
module ExampleServer
|
4
|
+
include EM::P::ObjectProtocol
|
5
|
+
end
|
4
6
|
|
5
7
|
module Domodoro
|
6
8
|
describe Client do
|
7
9
|
include EM::MiniTest::Spec
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
EM.add_timer(0.2) do
|
19
|
-
mocha_verify
|
20
|
-
done!
|
21
|
-
end
|
22
|
-
|
23
|
-
wait!
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'calls .break when receives :stop', :timeout => 0.3 do
|
27
|
-
EM.start_server '127.0.0.1', 12345, ExampleServer do |conn|
|
28
|
-
conn.send_data ":stop\n"
|
29
|
-
end
|
30
|
-
|
31
|
-
Client.expects(:break)
|
32
|
-
|
33
|
-
Client.start '127.0.0.1', 12345
|
34
|
-
|
35
|
-
EM.add_timer(0.2) do
|
36
|
-
mocha_verify
|
37
|
-
done!
|
38
|
-
end
|
39
|
-
|
40
|
-
wait!
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '.work' do
|
44
|
-
describe 'if sound is activated' do
|
45
|
-
it 'plays a sound', :timeout => 0.2 do
|
46
|
-
Config.stubs(:sound).returns true
|
47
|
-
Client.expects(:system)
|
48
|
-
Client.work
|
49
|
-
|
50
|
-
EM.add_timer(0.1) do
|
51
|
-
mocha_verify
|
52
|
-
done!
|
53
|
-
end
|
54
|
-
wait!
|
11
|
+
[
|
12
|
+
[:start, :work],
|
13
|
+
[:stop, :break],
|
14
|
+
[:lunch, :lunch],
|
15
|
+
[:go_home, :home],
|
16
|
+
].each do |message, action|
|
17
|
+
it "calls .#{action} when receives :#{message}", :timeout => 0.3 do
|
18
|
+
EM.start_server '127.0.0.1', 12345, ExampleServer do |conn|
|
19
|
+
conn.send_object({:current_action => ["08:30", message] })
|
55
20
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'otherwise' do
|
59
|
-
it 'does not play a sound', :timeout => 0.2 do
|
60
|
-
Config.stubs(:sound).returns false
|
61
|
-
Client.expects(:system).never
|
62
|
-
Client.work
|
63
21
|
|
64
|
-
|
65
|
-
mocha_verify
|
66
|
-
done!
|
67
|
-
end
|
68
|
-
wait!
|
69
|
-
end
|
70
|
-
end
|
22
|
+
Client.expects(action)
|
71
23
|
|
72
|
-
|
73
|
-
it 'displays a visual notification', :timeout => 0.2 do
|
74
|
-
Config.stubs(:visual).returns true
|
75
|
-
Notify.expects(:notify)
|
76
|
-
Client.work
|
24
|
+
Client.start '127.0.0.1', 12345
|
77
25
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
wait!
|
26
|
+
EM.add_timer(0.2) do
|
27
|
+
mocha_verify
|
28
|
+
done!
|
83
29
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'otherwise' do
|
87
|
-
it 'does not display any visual notification', :timeout => 0.2 do
|
88
|
-
Config.stubs(:visual).returns false
|
89
|
-
Notify.expects(:notify).never
|
90
|
-
Client.work
|
91
30
|
|
92
|
-
|
93
|
-
mocha_verify
|
94
|
-
done!
|
95
|
-
end
|
96
|
-
wait!
|
97
|
-
end
|
31
|
+
wait!
|
98
32
|
end
|
99
33
|
end
|
100
34
|
|
101
|
-
|
102
|
-
describe
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
35
|
+
%w(work break lunch home).each do |action|
|
36
|
+
describe ".#{action}" do
|
37
|
+
describe 'if sound is activated' do
|
38
|
+
it 'plays a sound', :timeout => 0.3 do
|
39
|
+
Config.stubs(:sound).returns true
|
40
|
+
Client.expects(:system)
|
41
|
+
Client.send action
|
42
|
+
|
43
|
+
EM.add_timer(0.2) do
|
44
|
+
mocha_verify
|
45
|
+
done!
|
46
|
+
end
|
47
|
+
wait!
|
111
48
|
end
|
112
|
-
wait!
|
113
49
|
end
|
114
50
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
51
|
+
describe 'otherwise' do
|
52
|
+
it 'does not play a sound', :timeout => 0.2 do
|
53
|
+
Config.stubs(:sound).returns false
|
54
|
+
Client.expects(:system).never
|
55
|
+
Client.send action
|
56
|
+
|
57
|
+
EM.add_timer(0.1) do
|
58
|
+
mocha_verify
|
59
|
+
done!
|
60
|
+
end
|
61
|
+
wait!
|
126
62
|
end
|
127
|
-
wait!
|
128
63
|
end
|
129
|
-
end
|
130
64
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
65
|
+
describe 'if visual is activated' do
|
66
|
+
it 'displays a visual notification', :timeout => 0.2 do
|
67
|
+
Config.stubs(:visual).returns true
|
68
|
+
Notify.expects(:notify)
|
69
|
+
Client.send action
|
70
|
+
|
71
|
+
EM.add_timer(0.1) do
|
72
|
+
mocha_verify
|
73
|
+
done!
|
74
|
+
end
|
75
|
+
wait!
|
140
76
|
end
|
141
|
-
wait!
|
142
77
|
end
|
143
|
-
end
|
144
78
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
79
|
+
describe 'otherwise' do
|
80
|
+
it 'does not display any visual notification', :timeout => 0.2 do
|
81
|
+
Config.stubs(:visual).returns false
|
82
|
+
Notify.expects(:notify).never
|
83
|
+
Client.send action
|
84
|
+
|
85
|
+
EM.add_timer(0.1) do
|
86
|
+
mocha_verify
|
87
|
+
done!
|
88
|
+
end
|
89
|
+
wait!
|
154
90
|
end
|
155
|
-
wait!
|
156
91
|
end
|
157
92
|
end
|
158
93
|
end
|
94
|
+
|
159
95
|
end
|
160
96
|
end
|