time_distribution 2.1.3 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/time_distribution/task.rb +17 -1
- data/lib/time_distribution/version.rb +1 -1
- data/lib/time_distribution/work_day.rb +21 -2
- data/lib/time_distribution/work_day_collection.rb +4 -0
- data/spec/task_spec.rb +23 -0
- data/spec/work_day_collection_spec.rb +50 -1
- data/spec/work_day_spec.rb +93 -56
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9692efc1b44adc211fba77adeccdafa2430c81d2
|
4
|
+
data.tar.gz: e7978438e95415dfe89328420cbfdfbd6acb7331
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f72a82d439b9f0a2e964d22caf2478a8a5d72d4886f57a0958a238ab01159a3055c76163083892e85a448d1a2a619f9bee3e3023ef6bc86bdcabdc26b5aa70
|
7
|
+
data.tar.gz: 4d88e5afb1142fa65d999b990cc8a53bf43519e48a46a767b1432cb0df4c6b68956c377ee441f56ccbe86aa4c0be62640e2d651f395d0f348652ec433135ad74
|
@@ -4,6 +4,14 @@ module TimeDistribution
|
|
4
4
|
class Task
|
5
5
|
attr_reader :subject, :time_taken, :desc
|
6
6
|
|
7
|
+
def self.from_map(map_data)
|
8
|
+
self.new(
|
9
|
+
map_data['subject'].to_sym,
|
10
|
+
map_data['duration'],
|
11
|
+
map_data['description']
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
7
15
|
# @param [#to_s] subject The subject on which the task was completed. E.g. A course or project.
|
8
16
|
# @param [#to_s] time_taken The amount of time taken on the task (Compatible with +ChronicDuration+ parsing, or a range of times that conform to +Chronic+ parsing).
|
9
17
|
# @param [#to_s] desc The task's description.
|
@@ -13,6 +21,14 @@ module TimeDistribution
|
|
13
21
|
@desc = desc
|
14
22
|
end
|
15
23
|
|
24
|
+
def ==(other)
|
25
|
+
(
|
26
|
+
other.subject == @subject &&
|
27
|
+
other.time_taken == @time_taken &&
|
28
|
+
other.desc == @desc
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
16
32
|
def to_s() "#{to_headline}: #{to_desc}" end
|
17
33
|
|
18
34
|
def to_desc() @desc.strip end
|
@@ -43,4 +59,4 @@ module TimeDistribution
|
|
43
59
|
)
|
44
60
|
end
|
45
61
|
end
|
46
|
-
end
|
62
|
+
end
|
@@ -2,16 +2,35 @@ require 'chronic'
|
|
2
2
|
require 'ruby-duration'
|
3
3
|
|
4
4
|
require 'time_distribution/task_list'
|
5
|
+
require 'time_distribution/task'
|
5
6
|
|
6
7
|
module TimeDistribution
|
7
8
|
class WorkDay
|
8
9
|
attr_reader :date, :tasks
|
9
10
|
|
11
|
+
def self.from_map(map_data)
|
12
|
+
self.new(
|
13
|
+
map_data['date'],
|
14
|
+
*(map_data['tasks'].map { |t| Task.from_map t })
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
10
18
|
# @param [#to_s] date Date of this work day in +Chronic+ compatible format.
|
11
19
|
# @param [Array<Task>] tasks List of tasks done in this work day. Defaults to an empty list.
|
12
20
|
def initialize(date, *tasks)
|
13
21
|
@date = Chronic.parse(date)
|
14
|
-
@tasks =
|
22
|
+
@tasks = if tasks.length == 1 && !tasks.first.is_a?(Task)
|
23
|
+
TaskList.new(*tasks)
|
24
|
+
else
|
25
|
+
TaskList.new(tasks)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other)
|
30
|
+
(
|
31
|
+
@date == other.date &&
|
32
|
+
@tasks == other.tasks
|
33
|
+
)
|
15
34
|
end
|
16
35
|
|
17
36
|
# @param [Task] task Adds +task+ to the list of tasks completed on this work day.
|
@@ -44,4 +63,4 @@ module TimeDistribution
|
|
44
63
|
)
|
45
64
|
end
|
46
65
|
end
|
47
|
-
end
|
66
|
+
end
|
@@ -12,6 +12,10 @@ module TimeDistribution
|
|
12
12
|
|
13
13
|
MONTHS = [:january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december]
|
14
14
|
|
15
|
+
def self.from_map(map_data)
|
16
|
+
self.new(*map_data.map { |t| WorkDay.from_map t })
|
17
|
+
end
|
18
|
+
|
15
19
|
private
|
16
20
|
def provide_methods_for_setting_work_days_in_months
|
17
21
|
MONTHS.each do |m|
|
data/spec/task_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'support/spec_helper'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
require 'time_distribution/task'
|
4
5
|
require 'time_distribution/smart_duration'
|
@@ -6,6 +7,28 @@ require 'time_distribution/smart_duration'
|
|
6
7
|
include TimeDistribution
|
7
8
|
|
8
9
|
describe Task do
|
10
|
+
let(:yml_string_data) do
|
11
|
+
<<-END
|
12
|
+
subject: :time_distribution
|
13
|
+
duration: 3:38pm to 4pm
|
14
|
+
description: |
|
15
|
+
- Comment 1
|
16
|
+
- Comment 2
|
17
|
+
END
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe '#from_map' do
|
22
|
+
it 'works' do
|
23
|
+
map_data = YAML.load(yml_string_data)
|
24
|
+
patient = Task.from_map(map_data)
|
25
|
+
|
26
|
+
patient.subject.must_equal map_data['subject']
|
27
|
+
patient.time_taken.must_equal SmartDuration.parse(map_data['duration'])
|
28
|
+
patient.desc.must_equal map_data['description']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
9
32
|
describe '#new' do
|
10
33
|
it 'works for three arguments' do
|
11
34
|
x_subject = 'subject'
|
@@ -1,9 +1,58 @@
|
|
1
1
|
require_relative 'support/spec_helper'
|
2
2
|
|
3
3
|
require 'time_distribution/work_day_collection'
|
4
|
+
require 'time_distribution/work_day'
|
4
5
|
|
5
6
|
include TimeDistribution
|
7
|
+
|
8
|
+
|
6
9
|
describe WorkDayCollection do
|
10
|
+
let(:yml_string_data) do
|
11
|
+
<<-END
|
12
|
+
-
|
13
|
+
date: April 21, 2016
|
14
|
+
tasks:
|
15
|
+
-
|
16
|
+
subject: :time_distribution
|
17
|
+
duration: 6:38pm to 7pm
|
18
|
+
description: |
|
19
|
+
- Comment 1
|
20
|
+
- Comment 2
|
21
|
+
-
|
22
|
+
subject: :aaaaaa
|
23
|
+
duration: 4:38am to 6pm
|
24
|
+
description: |
|
25
|
+
- Ahdkjlan akjdlnkfn
|
26
|
+
-
|
27
|
+
date: April 20, 2016
|
28
|
+
tasks:
|
29
|
+
-
|
30
|
+
subject: :time_distribution
|
31
|
+
duration: 6:38pm to 7pm
|
32
|
+
description: |
|
33
|
+
- Comment 3
|
34
|
+
- Comment 4
|
35
|
+
-
|
36
|
+
subject: :bbbbb
|
37
|
+
duration: 4:38am to 6pm
|
38
|
+
description: |
|
39
|
+
- jkljkljlkj syowueiorue
|
40
|
+
END
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe '#from_map' do
|
45
|
+
let(:patient) do
|
46
|
+
map_data = YAML.load(yml_string_data)
|
47
|
+
_patient = WorkDayCollection.from_map map_data
|
48
|
+
_patient.must_equal map_data.map { |t| WorkDay.from_map t }
|
49
|
+
_patient
|
50
|
+
end
|
51
|
+
it 'works' do
|
52
|
+
patient
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
7
56
|
describe '#new' do
|
8
57
|
it 'with days only' do
|
9
58
|
patient = WorkDayCollection.new('d1', 'd2')
|
@@ -295,4 +344,4 @@ END
|
|
295
344
|
}
|
296
345
|
)
|
297
346
|
end
|
298
|
-
end
|
347
|
+
end
|
data/spec/work_day_spec.rb
CHANGED
@@ -1,52 +1,89 @@
|
|
1
1
|
require_relative 'support/spec_helper'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
require 'time_distribution/work_day'
|
5
|
+
require 'time_distribution/task'
|
4
6
|
|
5
7
|
include TimeDistribution
|
8
|
+
|
9
|
+
|
6
10
|
describe WorkDay do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
let(:yml_string_data) do
|
12
|
+
<<-END
|
13
|
+
date: April 21, 2016
|
14
|
+
tasks:
|
15
|
+
-
|
16
|
+
subject: :time_distribution
|
17
|
+
duration: 6:38pm to 7pm
|
18
|
+
description: |
|
19
|
+
- Comment 1
|
20
|
+
- Comment 2
|
21
|
+
-
|
22
|
+
subject: :aaaaaa
|
23
|
+
duration: 4:38am to 6pm
|
24
|
+
description: |
|
25
|
+
- Ahdkjlan akjdlnkfn
|
26
|
+
END
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
describe '#from_map' do
|
31
|
+
let(:patient) do
|
32
|
+
map_data = YAML.load(yml_string_data)
|
33
|
+
_patient = WorkDay.from_map map_data
|
34
|
+
_patient.date.must_equal Chronic.parse(map_data['date'])
|
35
|
+
_patient.tasks.must_equal map_data['tasks'].map { |t| Task.from_map t }
|
36
|
+
_patient
|
37
|
+
end
|
38
|
+
it 'works' do
|
39
|
+
patient
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
let(:x_tasks) { [MiniTest::Mock.new, MiniTest::Mock.new] }
|
45
|
+
let(:x_date) { 'May 7, 2013' }
|
46
|
+
let(:patient) do
|
47
|
+
_patient = WorkDay.new x_date, *x_tasks
|
48
|
+
_patient.date.must_equal Chronic.parse(x_date)
|
49
|
+
_patient.tasks.must_equal x_tasks
|
50
|
+
_patient
|
16
51
|
end
|
52
|
+
|
53
|
+
|
17
54
|
describe 'to_hours' do
|
18
55
|
it 'works without argument' do
|
19
|
-
|
20
|
-
|
21
|
-
|
56
|
+
x_tasks[0].expect(:to_hours, 1.1)
|
57
|
+
x_tasks[1].expect(:to_hours, 2.6)
|
58
|
+
patient.to_hours.must_equal 1.1 + 2.6
|
22
59
|
end
|
23
60
|
it 'works with arguments' do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
61
|
+
x_tasks[0].expect(:to_hours, 1.1)
|
62
|
+
x_tasks[1].expect(:to_hours, 2.6)
|
63
|
+
x_tasks[0].expect(:subject, :relevant_task)
|
64
|
+
x_tasks[1].expect(:subject, :irrelevant_task)
|
65
|
+
patient.to_hours(:relevant_task).must_equal 1.1
|
66
|
+
|
67
|
+
x_tasks[0].expect(:to_hours, 1.1)
|
68
|
+
x_tasks[1].expect(:to_hours, 2.6)
|
69
|
+
x_tasks[0].expect(:subject, :relevant_task)
|
70
|
+
x_tasks[1].expect(:subject, :irrelevant_task)
|
71
|
+
patient.to_hours(:irrelevant_task).must_equal 2.6
|
72
|
+
|
73
|
+
x_tasks[0].expect(:to_hours, 1.1)
|
74
|
+
x_tasks[1].expect(:to_hours, 2.6)
|
75
|
+
x_tasks[0].expect(:subject, :relevant_task)
|
76
|
+
x_tasks[1].expect(:subject, :irrelevant_task)
|
77
|
+
patient.to_hours(:relevant_task, :irrelevant_task).must_equal 1.1 + 2.6
|
41
78
|
end
|
42
79
|
end
|
43
80
|
describe 'to_md' do
|
44
81
|
it 'works' do
|
45
|
-
|
46
|
-
|
47
|
-
|
82
|
+
x_tasks[0].expect(:to_s, 'Task 1')
|
83
|
+
x_tasks[1].expect(:to_s, 'Task 2')
|
84
|
+
patient.to_md.must_equal (
|
48
85
|
<<-END
|
49
|
-
#{
|
86
|
+
#{x_date}
|
50
87
|
============================
|
51
88
|
- Task 1
|
52
89
|
- Task 2
|
@@ -57,8 +94,8 @@ END
|
|
57
94
|
describe '#add_task!' do
|
58
95
|
it 'works' do
|
59
96
|
t3 = MiniTest::Mock.new
|
60
|
-
|
61
|
-
|
97
|
+
patient.add_task!(t3).must_equal patient
|
98
|
+
patient.tasks.must_equal (x_tasks << t3)
|
62
99
|
end
|
63
100
|
end
|
64
101
|
describe 'time_worked' do
|
@@ -66,34 +103,34 @@ END
|
|
66
103
|
it 'when all tasks have the same subject' do
|
67
104
|
time_taken_for_each_task = 23
|
68
105
|
x_subject = 'my subject'
|
69
|
-
|
106
|
+
x_tasks.each do |mock_task|
|
70
107
|
mock_task.expect(:subject, x_subject)
|
71
108
|
mock_task.expect(:time_taken, time_taken_for_each_task)
|
72
109
|
end
|
73
|
-
|
110
|
+
patient.time_worked.must_equal ({x_subject => (Duration.new(x_tasks.length * time_taken_for_each_task)) })
|
74
111
|
end
|
75
112
|
it 'when more than one subject is present' do
|
76
113
|
time_taken_for_each_task = 23
|
77
114
|
subject_1 = 'subject 1'
|
78
|
-
|
115
|
+
x_tasks.each do |mock_task|
|
79
116
|
mock_task.expect(:subject, subject_1)
|
80
117
|
mock_task.expect(:time_taken, time_taken_for_each_task)
|
81
118
|
end
|
82
|
-
num_subject_1_tasks =
|
119
|
+
num_subject_1_tasks = x_tasks.length
|
83
120
|
t3 = MiniTest::Mock.new
|
84
121
|
subject_2 = 'subject 2'
|
85
122
|
t3.expect(:subject, subject_2)
|
86
123
|
t3.expect(:time_taken, time_taken_for_each_task)
|
87
|
-
|
124
|
+
x_tasks << t3
|
88
125
|
t4 = MiniTest::Mock.new
|
89
126
|
subject_3 = 'subject 3'
|
90
127
|
t4.expect(:subject, subject_3)
|
91
128
|
t4.expect(:time_taken, time_taken_for_each_task)
|
92
|
-
|
129
|
+
x_tasks << t4
|
93
130
|
|
94
|
-
|
131
|
+
patient = WorkDay.new x_date, x_tasks
|
95
132
|
|
96
|
-
|
133
|
+
patient.time_worked.must_equal (
|
97
134
|
{
|
98
135
|
subject_1 => Duration.new(num_subject_1_tasks * time_taken_for_each_task),
|
99
136
|
subject_2 => Duration.new(time_taken_for_each_task),
|
@@ -105,24 +142,24 @@ END
|
|
105
142
|
it 'returns a hash of duration sums when given a list of subjects' do
|
106
143
|
time_taken_for_each_task = 23
|
107
144
|
subject_1 = 'subject 1'
|
108
|
-
|
145
|
+
x_tasks.each do |mock_task|
|
109
146
|
mock_task.expect(:subject, subject_1)
|
110
147
|
mock_task.expect(:time_taken, time_taken_for_each_task)
|
111
148
|
end
|
112
|
-
num_subject_1_tasks =
|
149
|
+
num_subject_1_tasks = x_tasks.length
|
113
150
|
t3 = MiniTest::Mock.new
|
114
151
|
subject_2 = 'subject 2'
|
115
152
|
t3.expect(:subject, subject_2)
|
116
153
|
t3.expect(:time_taken, time_taken_for_each_task)
|
117
|
-
|
154
|
+
x_tasks << t3
|
118
155
|
t4 = MiniTest::Mock.new
|
119
156
|
subject_3 = 'subject 3'
|
120
157
|
t4.expect(:subject, subject_3)
|
121
|
-
|
158
|
+
x_tasks << t4
|
122
159
|
|
123
|
-
|
160
|
+
patient = WorkDay.new x_date, x_tasks
|
124
161
|
|
125
|
-
|
162
|
+
patient.time_worked(subject_1, subject_2).must_equal (
|
126
163
|
{
|
127
164
|
subject_1 => Duration.new(num_subject_1_tasks * time_taken_for_each_task),
|
128
165
|
subject_2 => Duration.new(time_taken_for_each_task)
|
@@ -133,27 +170,27 @@ END
|
|
133
170
|
it 'as a scalar' do
|
134
171
|
time_taken_for_each_task = 23
|
135
172
|
subject_1 = 'subject 1'
|
136
|
-
|
173
|
+
x_tasks.each do |mock_task|
|
137
174
|
mock_task.expect(:subject, subject_1)
|
138
175
|
mock_task.expect(:time_taken, time_taken_for_each_task)
|
139
176
|
end
|
140
|
-
num_subject_1_tasks =
|
177
|
+
num_subject_1_tasks = x_tasks.length
|
141
178
|
t3 = MiniTest::Mock.new
|
142
179
|
subject_2 = 'subject 2'
|
143
180
|
t3.expect(:subject, subject_2)
|
144
181
|
t3.expect(:time_taken, time_taken_for_each_task)
|
145
|
-
|
182
|
+
x_tasks << t3
|
146
183
|
t4 = MiniTest::Mock.new
|
147
184
|
subject_3 = 'subject 3'
|
148
185
|
t4.expect(:subject, subject_3)
|
149
|
-
|
186
|
+
x_tasks << t4
|
150
187
|
|
151
|
-
|
188
|
+
patient = WorkDay.new x_date, x_tasks
|
152
189
|
|
153
|
-
|
190
|
+
patient.time_worked(subject_1).must_equal (
|
154
191
|
{subject_1 => Duration.new(num_subject_1_tasks * time_taken_for_each_task)}
|
155
192
|
)
|
156
193
|
end
|
157
194
|
end
|
158
195
|
end
|
159
|
-
end
|
196
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_distribution
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.5.1
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Gem for creating time distribution management systems
|
@@ -180,4 +180,3 @@ test_files:
|
|
180
180
|
- spec/time_spec.rb
|
181
181
|
- spec/work_day_collection_spec.rb
|
182
182
|
- spec/work_day_spec.rb
|
183
|
-
has_rdoc:
|