todo-void 0.1 → 0.1.1.pre
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.
- data/interactors/status_changes_interactor.rb +6 -2
- data/interactors/todo_interactor.rb +1 -1
- data/lib/todo_filter.rb +8 -1
- data/lib/todo_list.rb +4 -34
- data/lib/todo_store.rb +15 -12
- metadata +5 -5
@@ -21,8 +21,12 @@ class StatusChangesInteractor
|
|
21
21
|
|
22
22
|
private
|
23
23
|
def change_todo_status(hash, status)
|
24
|
-
todos = @list
|
25
|
-
|
24
|
+
todos = TodoFilter.new(@list)
|
25
|
+
.with_hash(hash)
|
26
|
+
.with_status([:finished, :started, :pending])
|
27
|
+
.recent
|
28
|
+
.execute
|
29
|
+
todos = todos.to_a
|
26
30
|
|
27
31
|
case todos.length
|
28
32
|
when 0
|
data/lib/todo_filter.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
require_relative './todo_list'
|
2
|
+
|
1
3
|
class TodoFilter
|
2
4
|
def initialize(todos)
|
3
5
|
@todos = todos.dup
|
4
6
|
@todos.reject! { |todo| todo.status == :deleted }
|
5
7
|
end
|
6
8
|
|
9
|
+
def with_hash(search)
|
10
|
+
@todos.reject! { |todo| not /^#{search}/.match(todo.id) }
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
7
14
|
def with_status(statuses)
|
8
15
|
result = []
|
9
16
|
statuses.each do |status|
|
@@ -24,7 +31,7 @@ class TodoFilter
|
|
24
31
|
end
|
25
32
|
|
26
33
|
def execute
|
27
|
-
@todos
|
34
|
+
TodoList.new(@todos)
|
28
35
|
end
|
29
36
|
|
30
37
|
private
|
data/lib/todo_list.rb
CHANGED
@@ -1,38 +1,8 @@
|
|
1
|
-
|
2
|
-
attr_reader :todo
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@todo = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def add(todo)
|
9
|
-
@todo.store(todo.id, todo)
|
10
|
-
end
|
11
|
-
|
12
|
-
def find(search)
|
13
|
-
list = TodoList.new
|
14
|
-
@todo.each do |id, todo|
|
15
|
-
list.add todo if /^#{search}/.match id
|
16
|
-
end
|
17
|
-
list
|
18
|
-
end
|
19
|
-
|
20
|
-
def length
|
21
|
-
@todo.length
|
22
|
-
end
|
23
|
-
|
24
|
-
def empty?
|
25
|
-
@todo.length == 0
|
26
|
-
end
|
1
|
+
require 'set'
|
27
2
|
|
3
|
+
class TodoList < Set
|
28
4
|
def update(todo)
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_array
|
34
|
-
todos = []
|
35
|
-
@todo.each do |id, todo| todos << todo end
|
36
|
-
todos
|
5
|
+
delete(todo)
|
6
|
+
add(todo)
|
37
7
|
end
|
38
8
|
end
|
data/lib/todo_store.rb
CHANGED
@@ -24,24 +24,27 @@ class TodoStore
|
|
24
24
|
|
25
25
|
private
|
26
26
|
def read
|
27
|
-
@list = TodoList.new
|
28
|
-
|
29
27
|
FileUtils.touch(todo_file)
|
30
28
|
data = CSV.read(todo_file)
|
31
|
-
data.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
todos = data.map do |raw_todo|
|
30
|
+
convert_raw_todo(raw_todo)
|
31
|
+
end
|
32
|
+
@list = TodoList.new(todos)
|
33
|
+
end
|
34
|
+
|
35
|
+
def convert_raw_todo(raw_todo)
|
36
|
+
todo = Todo.new raw_todo[0]
|
37
|
+
unless raw_todo[2].nil?
|
38
|
+
todo.finished_at = DateTime.parse(raw_todo[2]).to_time
|
38
39
|
end
|
40
|
+
todo.status = raw_todo[1].to_sym
|
41
|
+
todo
|
39
42
|
end
|
40
|
-
|
43
|
+
|
41
44
|
def write
|
42
45
|
CSV.open(todo_file, "w") do |csv|
|
43
|
-
@list.
|
44
|
-
csv << [
|
46
|
+
@list.each do |todo|
|
47
|
+
csv << [todo.description, todo.status, todo.finished_at]
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-void
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Curth
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
homepage: http://rubygems.org/gems/todo-void
|
96
96
|
licenses:
|
97
97
|
- MIT
|
98
|
-
post_install_message:
|
98
|
+
post_install_message: Enter t 'Mowing the lawn' to create your first task!
|
99
99
|
rdoc_options: []
|
100
100
|
require_paths:
|
101
101
|
- lib
|
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
none: false
|
110
110
|
requirements:
|
111
|
-
- - ! '
|
111
|
+
- - ! '>'
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version:
|
113
|
+
version: 1.3.1
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
116
|
rubygems_version: 1.8.24
|