portera 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +5 -0
- data/lib/portera/event.rb +13 -7
- data/lib/portera/participant.rb +17 -2
- data/lib/portera/version.rb +1 -1
- data/test/coalesced.rb +163 -0
- data/test/invalid_days.rb +39 -0
- metadata +14 -12
data/CHANGELOG.markdown
CHANGED
data/lib/portera/event.rb
CHANGED
@@ -107,24 +107,30 @@ module Portera
|
|
107
107
|
# Note assumes timeslots are appended in ascending order by range.begin
|
108
108
|
# TODO could use some refactoring
|
109
109
|
def coalesced
|
110
|
-
|
111
|
-
inject(
|
110
|
+
last_slot = nil
|
111
|
+
coales = inject(self.class.new) do |accum, this_slot|
|
112
112
|
if last_slot
|
113
113
|
rng = this_slot.range
|
114
114
|
last_rng = last_slot.range
|
115
115
|
if (rng.intersects?(last_rng) || rng.succeeds?(last_rng)) &&
|
116
116
|
(this_slot.participants == last_slot.participants)
|
117
|
-
Timeslot.new(
|
118
|
-
|
117
|
+
last_slot = Timeslot.new(
|
118
|
+
(last_rng.begin...rng.end),
|
119
|
+
this_slot.participants
|
120
|
+
)
|
119
121
|
else
|
120
122
|
accum << last_slot
|
121
|
-
this_slot
|
123
|
+
last_slot = this_slot
|
122
124
|
end
|
123
125
|
else
|
124
|
-
this_slot
|
126
|
+
last_slot = this_slot
|
125
127
|
end
|
128
|
+
accum
|
126
129
|
end
|
127
|
-
|
130
|
+
if last_slot
|
131
|
+
coales << last_slot
|
132
|
+
end
|
133
|
+
coales
|
128
134
|
end
|
129
135
|
|
130
136
|
# sort timeslot availability by
|
data/lib/portera/participant.rb
CHANGED
@@ -59,6 +59,13 @@ module Portera
|
|
59
59
|
:thu => 4,
|
60
60
|
:fri => 5,
|
61
61
|
:sat => 6,
|
62
|
+
:su => 0,
|
63
|
+
:m => 1,
|
64
|
+
:tu => 2,
|
65
|
+
:w => 3,
|
66
|
+
:th => 4,
|
67
|
+
:f => 5,
|
68
|
+
:sa => 6,
|
62
69
|
:Sunday => 0,
|
63
70
|
:Monday => 1,
|
64
71
|
:Tuesday => 2,
|
@@ -72,7 +79,14 @@ module Portera
|
|
72
79
|
:Wed => 3,
|
73
80
|
:Thu => 4,
|
74
81
|
:Fri => 5,
|
75
|
-
:Sat => 6
|
82
|
+
:Sat => 6,
|
83
|
+
:Su => 0,
|
84
|
+
:M => 1,
|
85
|
+
:Tu => 2,
|
86
|
+
:W => 3,
|
87
|
+
:Th => 4,
|
88
|
+
:F => 5,
|
89
|
+
:Sa => 6
|
76
90
|
}
|
77
91
|
|
78
92
|
def initialize(collect,utc_offset=nil)
|
@@ -107,7 +121,8 @@ module Portera
|
|
107
121
|
private
|
108
122
|
|
109
123
|
def to_weekday(day)
|
110
|
-
|
124
|
+
return day if (0..6).include?(day)
|
125
|
+
Days[day] or raise ArgumentError, "Unknown day: #{day}"
|
111
126
|
end
|
112
127
|
|
113
128
|
end
|
data/lib/portera/version.rb
CHANGED
data/test/coalesced.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require File.expand_path('test_helper',File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module CoalescedTests
|
4
|
+
|
5
|
+
module Helpers
|
6
|
+
|
7
|
+
def new_participants
|
8
|
+
('A'..'Z').map {|name| Portera::Participant.new(name) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def participant_set(partic, indexes)
|
12
|
+
indexes = Array(indexes)
|
13
|
+
::Set.new( indexes.map {|i| partic[i]} )
|
14
|
+
end
|
15
|
+
|
16
|
+
def new_timeslot(range, partic)
|
17
|
+
range.extend(Tempr::DateTimeRange)
|
18
|
+
Portera::Timeslot.new( range , partic )
|
19
|
+
end
|
20
|
+
|
21
|
+
def assert_timeslot(exp_range, exp_partic, act)
|
22
|
+
assert exp_range == act.range &&
|
23
|
+
exp_partic == act.participants,
|
24
|
+
"Timeslot expected to be for range #{exp_range} "+
|
25
|
+
"with participants #{exp_partic.to_a}, instead was " +
|
26
|
+
"#{act}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'coalescing' do
|
32
|
+
include Helpers
|
33
|
+
|
34
|
+
before do
|
35
|
+
@subject = Portera::TimeslotEnum.new
|
36
|
+
@all_partic = new_participants
|
37
|
+
|
38
|
+
[ new_timeslot(
|
39
|
+
( Time.utc(2012,01,02,03,00,00)...
|
40
|
+
Time.utc(2012,01,02,03,30,00)),
|
41
|
+
participant_set(@all_partic, (0..5))
|
42
|
+
),
|
43
|
+
new_timeslot( # coalesce
|
44
|
+
( Time.utc(2012,01,02,03,15,00)...
|
45
|
+
Time.utc(2012,01,02,03,45,00)),
|
46
|
+
participant_set(@all_partic, (0..5))
|
47
|
+
),
|
48
|
+
new_timeslot( # coalesce
|
49
|
+
( Time.utc(2012,01,02,03,44,59)...
|
50
|
+
Time.utc(2012,01,02,04,00,00)),
|
51
|
+
participant_set(@all_partic, (0..5))
|
52
|
+
),
|
53
|
+
new_timeslot( # not coalesce
|
54
|
+
( Time.utc(2012,01,02,03,45,00)...
|
55
|
+
Time.utc(2012,01,02,04,00,00)),
|
56
|
+
participant_set(@all_partic, (4..9))
|
57
|
+
),
|
58
|
+
new_timeslot( # not coalesce
|
59
|
+
( Time.utc(2012,01,02,03,45,00)...
|
60
|
+
Time.utc(2012,01,02,04,00,00)),
|
61
|
+
participant_set(@all_partic, (10..15))
|
62
|
+
),
|
63
|
+
new_timeslot( # coalesce
|
64
|
+
( Time.utc(2012,01,02,04,00,00)...
|
65
|
+
Time.utc(2012,01,02,04,15,00)),
|
66
|
+
participant_set(@all_partic, (10..15))
|
67
|
+
),
|
68
|
+
new_timeslot( # coalesce
|
69
|
+
( Time.utc(2012,01,02,04,15,00)...
|
70
|
+
Time.utc(2012,01,02,04,30,00)),
|
71
|
+
participant_set(@all_partic, (10..15))
|
72
|
+
),
|
73
|
+
new_timeslot( # not coalesce
|
74
|
+
( Time.utc(2012,01,02,04,30,00)...
|
75
|
+
Time.utc(2012,01,02,05,00,00)),
|
76
|
+
participant_set(@all_partic, (15..16))
|
77
|
+
),
|
78
|
+
new_timeslot( # not coalesce
|
79
|
+
( Time.utc(2012,01,02,05,30,00)...
|
80
|
+
Time.utc(2012,01,02,06,00,00)),
|
81
|
+
participant_set(@all_partic, (15..16))
|
82
|
+
),
|
83
|
+
new_timeslot( # not coalesce
|
84
|
+
( Time.utc(2012,01,02,06,30,00)...
|
85
|
+
Time.utc(2012,01,02,07,00,00)),
|
86
|
+
participant_set(@all_partic, (16..17))
|
87
|
+
),
|
88
|
+
].each do |slot|
|
89
|
+
@subject << slot
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should have the correct number of coalesced timeslots' do
|
95
|
+
actual = @subject.coalesced.to_a
|
96
|
+
puts actual
|
97
|
+
assert_equal 6, actual.count
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should coalesce overlapping ranges with same participants' do
|
101
|
+
actual = @subject.coalesced.to_a
|
102
|
+
assert_timeslot ( Time.utc(2012,01,02,03,00,00)...
|
103
|
+
Time.utc(2012,01,02,04,00,00)),
|
104
|
+
participant_set(@all_partic, (0..5)),
|
105
|
+
actual[0]
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not coalesce overlapping ranges with different participants' do
|
109
|
+
actual = @subject.coalesced.to_a
|
110
|
+
assert_timeslot ( Time.utc(2012,01,02,03,45,00)...
|
111
|
+
Time.utc(2012,01,02,04,00,00)),
|
112
|
+
participant_set(@all_partic, (4..9)),
|
113
|
+
actual[1]
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should coalesce adjacent ranges with same participants' do
|
117
|
+
actual = @subject.coalesced.to_a
|
118
|
+
assert_timeslot ( Time.utc(2012,01,02,03,45,00)...
|
119
|
+
Time.utc(2012,01,02,04,30,00)),
|
120
|
+
participant_set(@all_partic, (10..15)),
|
121
|
+
actual[2]
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should not coalesce adjacent ranges with different participants' do
|
125
|
+
actual = @subject.coalesced.to_a
|
126
|
+
assert_timeslot ( Time.utc(2012,01,02,04,30,00)...
|
127
|
+
Time.utc(2012,01,02,05,00,00)),
|
128
|
+
participant_set(@all_partic, (15..16)),
|
129
|
+
actual[3]
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should not coalesce non-overlapping non-adjacent ranges with same participants' do
|
133
|
+
actual = @subject.coalesced.to_a
|
134
|
+
assert_timeslot ( Time.utc(2012,01,02,05,30,00)...
|
135
|
+
Time.utc(2012,01,02,06,00,00)),
|
136
|
+
participant_set(@all_partic, (15..16)),
|
137
|
+
actual[4]
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should not coalesce non-overlapping non-adjacent ranges with different participants' do
|
141
|
+
actual = @subject.coalesced.to_a
|
142
|
+
assert_timeslot ( Time.utc(2012,01,02,06,30,00)...
|
143
|
+
Time.utc(2012,01,02,07,00,00)),
|
144
|
+
participant_set(@all_partic, (16..17)),
|
145
|
+
actual[5]
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "nil case" do
|
151
|
+
before do
|
152
|
+
@subject = Portera::TimeslotEnum.new
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should have zero timeslots' do
|
156
|
+
actual = @subject.coalesced
|
157
|
+
assert actual.none?,
|
158
|
+
"Expected coalesced to return no timeslots; was #{actual.to_a.count}"
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path('test_helper',File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'invalid days' do
|
4
|
+
|
5
|
+
let(:malcolm) do
|
6
|
+
Portera::Participant.new('Malcolm Reynolds').available do
|
7
|
+
on(:Mon, :from => "15:00", :to => "18:00" )
|
8
|
+
on(:Wed, :from => "20:00", :to => "23:00" )
|
9
|
+
on(:Fs, :from => "16:00", :to => "19:00" )
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:hoban) do
|
14
|
+
Portera::Participant.new('Hoban Washburne').available do
|
15
|
+
on(:monday, :from => "15:00", :to => "18:00" )
|
16
|
+
on(:wednesday, :from => "20:00", :to => "23:00" )
|
17
|
+
on(7, :from => "15:00", :to => "18:30" )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:zoe) do
|
22
|
+
Portera::Participant.new('Zoe Washburne').available do
|
23
|
+
on([1, 2, -1], :from => "15:00", :to => "18:00" )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should raise ArgumentError when unknown symbol' do
|
28
|
+
assert_raises(ArgumentError) { malcolm }
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should raise ArgumentError when day > 6' do
|
32
|
+
assert_raises(ArgumentError) { hoban }
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should raise ArgumentError when day < 0' do
|
36
|
+
assert_raises(ArgumentError) { zoe }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: portera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tempr
|
16
|
-
requirement: &
|
16
|
+
requirement: &18516760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.1.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18516760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: erubis
|
27
|
-
requirement: &
|
27
|
+
requirement: &18516220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18516220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tilt
|
38
|
-
requirement: &
|
38
|
+
requirement: &18515680 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *18515680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: minitest
|
49
|
-
requirement: &
|
49
|
+
requirement: &18515240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *18515240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &18514820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *18514820
|
69
69
|
description: ''
|
70
70
|
email:
|
71
71
|
- ericgj72@gmail.com
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- lib/portera/version.rb
|
86
86
|
- lib/portera/views/simple.erb
|
87
87
|
- test/acceptance.rb
|
88
|
+
- test/coalesced.rb
|
89
|
+
- test/invalid_days.rb
|
88
90
|
- test/test_helper.rb
|
89
91
|
homepage: http://github.com/ericgj/portera
|
90
92
|
licenses: []
|