working_class 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ module WorkingClass
2
+
3
+ # A represantation of a Tasklist
4
+ #
5
+ # @attr_reader name [String] the name of the Tasklist
6
+ # @attr_reader tasks [Array<WorkingClass::Task>] the tasks of the Tasklist
7
+ class Tasklist
8
+
9
+ attr_reader :name
10
+
11
+ attr_reader :tasks
12
+
13
+ # Initializes a new Tasklist with a name and optional Tasks
14
+ #
15
+ # @param name [String] the tasklist name
16
+ # @param tasks [Array<WorkingClass::Task>] an array with Tasks
17
+ # @return [WorkingClass::Tasklist] the actual Tasklist object
18
+ #
19
+ def initialize(name, tasks = [])
20
+ @name = name
21
+ @tasks = tasks
22
+ end
23
+
24
+ # Returns all the upcoming tasks
25
+ #
26
+ # @return [Array<WorkingClass::Task>] an Array with the upcoming tasks
27
+ #
28
+ def upcoming_tasks
29
+ @tasks.select { |task| task.is_upcoming }
30
+ end
31
+
32
+ # Returns all the tasks that are due tomorrow
33
+ #
34
+ # @return [Array<WorkingClass::Task>] an Array with the tasks due tomorrow
35
+ #
36
+ def tasks_due_tomorrow
37
+ @tasks.select { |task| task.is_tomorrow }
38
+ end
39
+
40
+ # Returns all the finished tasks
41
+ #
42
+ # @return [Array<WorkingClass::Task>] an Array the finished tasks
43
+ #
44
+ def finished_tasks
45
+ @tasks.select { |task| task.is_finished }
46
+ end
47
+
48
+ # Returns all the unfinished tasks
49
+ #
50
+ # @return [Array<WorkingClass::Task>] an Array with the unfinished tasks
51
+ #
52
+ def unfinished_tasks
53
+ @tasks.select { |task| !task.is_finished }
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module WorkingClass
2
+ # The version of the gem.
3
+ # We use semantic versioning
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,3 @@
1
+ A cool todolist
2
+ ---
3
+ [ ] My Task Number 1
@@ -0,0 +1,3 @@
1
+ Groceries List
2
+ ---
3
+ [X] My finished Task
@@ -0,0 +1,4 @@
1
+ Development Todolist
2
+ ---
3
+ [ ]{12.12.15} Release WorkingClass
4
+ [x]{12.02.15} Yolo
@@ -0,0 +1,4 @@
1
+ Shopping List
2
+ ---
3
+ [ ]{12.01.2015} Buy some Jeans
4
+ [ ]{5.7.16}() Buy more Jeans
@@ -0,0 +1,5 @@
1
+ Another List Another Day
2
+ ---
3
+ [X](15.2.15) Yolo
4
+ [X]{16.2.15}(15.2.15 13:00) Yolo in the house
5
+
@@ -0,0 +1,5 @@
1
+ Yeah more examples
2
+ ---
3
+ [ ]{17.03.12}(-1) Twitter Downtime
4
+ [ ]{12.5.15}(-2 5:00) Another Task
5
+ [X]{12.3.15}(5:00) Remind me!!
@@ -0,0 +1,185 @@
1
+ require File.expand_path('../test_helper.rb', __FILE__)
2
+
3
+ class ParserTest < Minitest::Test
4
+
5
+ include WorkingClass
6
+
7
+ def load_example(example_name)
8
+ path = File.expand_path("../examples/#{example_name}.txt", __FILE__)
9
+ File.open(path, 'r').read()
10
+ end
11
+
12
+ def test_initialize
13
+ text = load_example('example_1')
14
+ parser = Parser.new(text)
15
+ assert_instance_of(Parser, parser)
16
+ end
17
+
18
+ def test_to_a_simple_task
19
+ text = load_example('example_1')
20
+ parser = Parser.new(text)
21
+ output = parser.to_h
22
+
23
+ assert_instance_of(Hash, output)
24
+ assert_instance_of(Array, output[:tasks])
25
+ assert_instance_of(Hash, output[:tasks].first)
26
+
27
+ assert_equal('A cool todolist', output[:name])
28
+ assert_equal(1, output[:tasks_count])
29
+ assert_equal('My Task Number 1', output[:tasks].first[:name])
30
+
31
+ assert(!output[:tasks].first[:is_finished])
32
+ assert_nil(output[:tasks].first[:date])
33
+ assert_nil(output[:tasks].first[:reminder])
34
+ end
35
+
36
+ def test_to_a_simple_finished_task
37
+ text = load_example('example_2')
38
+ parser = Parser.new(text)
39
+ output = parser.to_h
40
+
41
+ assert_instance_of(Hash, output)
42
+ assert_instance_of(Array, output[:tasks])
43
+ assert_instance_of(Hash, output[:tasks].first)
44
+
45
+ assert_equal('Groceries List', output[:name])
46
+ assert_equal(1, output[:tasks_count])
47
+
48
+ assert_equal('My finished Task', output[:tasks].first[:name])
49
+ assert(output[:tasks].first[:is_finished])
50
+ assert_nil(output[:tasks].first[:date])
51
+ assert_nil(output[:tasks].first[:reminder])
52
+ end
53
+
54
+ def test_to_a_task_with_date
55
+ text = load_example('example_3')
56
+ parser = Parser.new(text)
57
+ output = parser.to_h
58
+ task_1 = output[:tasks].first
59
+ task_2 = output[:tasks].last
60
+
61
+ assert_instance_of(Hash, output)
62
+ assert_instance_of(Array, output[:tasks])
63
+ assert_instance_of(Hash, task_1)
64
+ assert_instance_of(Hash, task_2)
65
+
66
+ assert_equal('Development Todolist', output[:name])
67
+ assert_equal(2, output[:tasks_count])
68
+
69
+ assert_equal('Release WorkingClass', task_1[:name])
70
+ assert(!task_1[:is_finished])
71
+ assert_equal(Date.new(2015, 12, 12), task_1[:date])
72
+ assert_nil(task_1[:reminder])
73
+
74
+ assert_equal('Yolo', task_2[:name])
75
+ assert(task_2[:is_finished])
76
+ assert_equal(Date.new(2015, 2, 12), task_2[:date])
77
+ assert_nil(task_2[:reminder])
78
+ end
79
+
80
+ def test_to_a_task_with_full_date
81
+ text = load_example('example_4')
82
+ parser = Parser.new(text)
83
+ output = parser.to_h
84
+ task_1 = output[:tasks].first
85
+ task_2 = output[:tasks].last
86
+
87
+ assert_instance_of(Hash, output)
88
+ assert_instance_of(Array, output[:tasks])
89
+ assert_instance_of(Hash, task_1)
90
+ assert_instance_of(Hash, task_2)
91
+
92
+ assert_equal('Shopping List', output[:name])
93
+ assert_equal(2, output[:tasks_count])
94
+
95
+ assert_equal('Buy some Jeans', task_1[:name])
96
+ assert(!task_1[:is_finished])
97
+ assert_equal(Date.new(2015, 1, 12), task_1[:date])
98
+ assert_nil(task_1[:reminder])
99
+
100
+ assert_equal('Buy more Jeans', task_2[:name])
101
+ assert(!task_2[:is_finished])
102
+ assert_equal(Date.new(2016, 7 ,5), task_2[:date])
103
+ assert_equal(DateTime.new(2016, 7, 5, 9, 0), task_2[:reminder])
104
+ end
105
+
106
+ def test_to_a_task_with_absolute_reminder
107
+ text = load_example('example_5')
108
+ parser = Parser.new(text)
109
+ output = parser.to_h
110
+ task_1 = output[:tasks].first
111
+ task_2 = output[:tasks].last
112
+
113
+ assert_instance_of(Hash, output)
114
+ assert_instance_of(Array, output[:tasks])
115
+ assert_instance_of(Hash, task_1)
116
+ assert_instance_of(Hash, task_2)
117
+
118
+ assert_equal('Another List Another Day', output[:name])
119
+ assert_equal(2, output[:tasks_count])
120
+
121
+ assert_equal('Yolo', task_1[:name])
122
+ assert(task_1[:is_finished])
123
+ assert_nil(task_1[:date])
124
+ assert_equal(DateTime.new(2015, 2, 15, 9, 0) ,task_1[:reminder])
125
+
126
+ assert_equal('Yolo in the house', task_2[:name])
127
+ assert(task_2[:is_finished])
128
+ assert_equal(Date.new(2015, 2, 16), task_2[:date])
129
+
130
+ assert_equal(DateTime.new(2015, 2, 15, 13, 0), task_2[:reminder])
131
+ end
132
+
133
+ def test_to_a_task_with_relative_reminder
134
+ text = load_example('example_6')
135
+ parser = Parser.new(text)
136
+ output = parser.to_h
137
+ task_1 = output[:tasks][0]
138
+ task_2 = output[:tasks][1]
139
+ task_3 = output[:tasks][2]
140
+
141
+ assert_instance_of(Hash, output)
142
+ assert_instance_of(Array, output[:tasks])
143
+ assert_instance_of(Hash, task_1)
144
+ assert_instance_of(Hash, task_2)
145
+
146
+ assert_equal('Yeah more examples', output[:name])
147
+ assert_equal(3, output[:tasks_count])
148
+
149
+ assert_equal('Twitter Downtime', task_1[:name])
150
+ assert(!task_1[:is_finished])
151
+ assert_equal(Date.new(2012, 3, 17), task_1[:date])
152
+ assert_equal(DateTime.new(2012, 3, 16, 9, 0) ,task_1[:reminder])
153
+
154
+ assert_equal('Another Task', task_2[:name])
155
+ assert(!task_2[:is_finished])
156
+ assert_equal(Date.new(2015, 5, 12), task_2[:date])
157
+ assert_equal(DateTime.new(2015, 5, 10, 5, 0) ,task_2[:reminder])
158
+
159
+ assert_equal('Remind me!!', task_3[:name])
160
+ assert(task_3[:is_finished])
161
+ assert_equal(Date.new(2015, 3, 12), task_3[:date])
162
+ assert_equal(DateTime.new(2015, 3, 12, 5, 0), task_3[:reminder])
163
+ end
164
+
165
+ def test_to_tasklist
166
+ text = load_example('example_5')
167
+ parser = Parser.new(text)
168
+ tasklist = parser.to_tasklist
169
+ task_1 = tasklist.tasks.first
170
+ task_2 = tasklist.tasks.last
171
+
172
+ assert_instance_of(Tasklist, tasklist)
173
+ assert_equal(2, tasklist.tasks.length)
174
+ assert_equal("Another List Another Day", tasklist.name)
175
+
176
+ assert_equal('Yolo', task_1.name)
177
+ assert(task_1.is_finished)
178
+ assert_nil(task_1.date)
179
+
180
+ assert_equal('Yolo in the house', task_2.name)
181
+ assert(task_2.is_finished)
182
+ assert_equal(Date.new(2015, 2, 16), task_2.date)
183
+
184
+ end
185
+ end
@@ -0,0 +1,108 @@
1
+ require File.expand_path('../test_helper.rb', __FILE__)
2
+
3
+ class TaskTest < Minitest::Test
4
+
5
+ include WorkingClass
6
+
7
+
8
+ def test_initialize
9
+ task = Task.new "Buy oranges"
10
+
11
+ assert_instance_of(Task, task)
12
+ assert_equal "Buy oranges", task.name
13
+ assert !task.is_finished?
14
+ assert_nil task.date
15
+ assert_nil task.reminder
16
+ end
17
+
18
+ def test_initialize_with_options
19
+ task = Task.new "Buy even more oranges", :is_finished => true, :reminder => DateTime.new,
20
+ :date => Date.new
21
+
22
+ assert_equal "Buy even more oranges", task.name
23
+ assert task.is_finished?
24
+ assert_instance_of DateTime, task.reminder
25
+ assert_instance_of Date, task.date
26
+ end
27
+
28
+ def test_is_upcoming_today
29
+ task = Task.new "Futurama Marathon", :date => Date.today
30
+
31
+ assert(task.is_upcoming)
32
+ end
33
+
34
+ def test_is_upcoming_tomorrow
35
+ task = Task.new "Eat healthy", :date => Date.today + 1
36
+
37
+ assert(task.is_upcoming)
38
+ end
39
+
40
+ def test_is_upcoming_yesterday
41
+ task = Task.new "task lists are great", :date => Date.today - 1
42
+
43
+ assert(!task.is_upcoming)
44
+ end
45
+
46
+ def test_is_upcoming_already_finished
47
+ task = Task.new "Backup all the files", :is_finished => true, :date => Date.today
48
+
49
+ assert(!task.is_upcoming)
50
+ end
51
+
52
+ def test_is_upcoming_already_finished_tomorrow
53
+ task = Task.new "Eat chips", :is_finished => true, :date => Date.today + 1
54
+
55
+ assert(!task.is_upcoming)
56
+ end
57
+
58
+ def test_is_upcoming_without_date
59
+ task = Task.new "Backup all the files"
60
+
61
+ assert(task.is_upcoming)
62
+ end
63
+
64
+ def test_is_tomorrow
65
+ task = Task.new "Eat chips", :date => Date.today + 1
66
+
67
+ assert(task.is_tomorrow)
68
+ end
69
+
70
+ def test_is_tomorrow_was_actually_yesterday
71
+ task = Task.new "Eat chips", :date => Date.today - 1
72
+
73
+ assert(!task.is_tomorrow)
74
+ end
75
+
76
+ def test_is_tomorrow_is_actually_next_week
77
+ task = Task.new "Eat chips", :date => Date.today + 9
78
+
79
+ assert(!task.is_tomorrow)
80
+ end
81
+
82
+ def test_is_tomorrow_without_a_date
83
+ task = Task.new "Eat chips"
84
+
85
+ assert(task.is_tomorrow)
86
+ end
87
+
88
+ def test_is_tomorrow_already_finished
89
+ task = Task.new "Eat chips", :is_finished => true, :date => Date.today + 1
90
+
91
+ assert(!task.is_tomorrow)
92
+ end
93
+
94
+ def test_alias_methods
95
+
96
+ task = Task.new "my awesome task"
97
+
98
+ assert_respond_to(task, :is_finished?)
99
+ assert_respond_to(task, :finished?)
100
+
101
+ assert_respond_to(task, :is_tomorrow?)
102
+ assert_respond_to(task, :tomorrow?)
103
+
104
+ assert_respond_to(task, :is_upcoming?)
105
+ assert_respond_to(task, :upcoming?)
106
+ end
107
+
108
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path('../test_helper.rb', __FILE__)
2
+
3
+ class TasklistTest < Minitest::Test
4
+
5
+ include WorkingClass
6
+
7
+ def test_initialize
8
+ tasklist = Tasklist.new('my list')
9
+
10
+ assert_instance_of(Array, tasklist.tasks)
11
+ assert_equal('my list', tasklist.name)
12
+ assert_equal(0, tasklist.tasks.length)
13
+ end
14
+
15
+ def test_upcoming_tasks
16
+ task_1 = Task.new("Task 1", :is_finished => true, :date => Date.today + 2)
17
+ task_2 = Task.new("Task 2", :date => Date.today)
18
+ task_3 = Task.new("Task 3", :is_finished => true, :date => Date.today - 1)
19
+ tasks = [task_1, task_2, task_3]
20
+
21
+ tasklist = Tasklist.new("example_task_list", tasks)
22
+ expected = [task_2]
23
+
24
+ assert_equal(expected, tasklist.upcoming_tasks)
25
+
26
+ end
27
+
28
+ def test_finished_tasks
29
+ task_1 = Task.new("Task 1", :is_finished => true)
30
+ task_2 = Task.new("Task 2")
31
+ task_3 = Task.new("Task 3", :is_finished => true)
32
+ tasks = [task_1, task_2, task_3]
33
+
34
+ tasklist = Tasklist.new("example_task_list", tasks)
35
+ expected = [task_1, task_3]
36
+
37
+ assert_equal(expected, tasklist.finished_tasks)
38
+ end
39
+
40
+ def test_tasks_due_tomorrow
41
+ task_1 = Task.new("Task 1", :is_finished => true, :date => Date.today + 1)
42
+ task_2 = Task.new("Task 2")
43
+ task_3 = Task.new("Task 3", :date => Date.today + 2)
44
+ task_4 = Task.new("Task 4", :date => Date.today + 1 )
45
+
46
+ tasks = [task_1, task_2, task_3, task_4]
47
+
48
+ tasklist = Tasklist.new("example_task_list", tasks)
49
+ expected = [task_2, task_4]
50
+
51
+ assert_equal(expected, tasklist.tasks_due_tomorrow)
52
+ end
53
+
54
+ def test_unfinished_tasks
55
+ task_1 = Task.new("Task 1", :is_finished => true)
56
+ task_2 = Task.new("Task 2")
57
+ task_3 = Task.new("Task 3")
58
+ task_4 = Task.new("Task 4", :is_finished => true)
59
+
60
+ tasks = [task_1, task_2, task_3, task_4]
61
+
62
+ tasklist = Tasklist.new("example_task_list", tasks)
63
+ expected = [task_2, task_3]
64
+
65
+ assert_equal(expected, tasklist.unfinished_tasks)
66
+ end
67
+
68
+
69
+ end