tudu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -86,8 +86,8 @@ $ tudu todos
86
86
  hige
87
87
  ~~~
88
88
 
89
- ### choose task from todo to doing
90
- * choose
89
+ ### choose task name. from todo to doing
90
+ * choose task_name
91
91
 
92
92
  ~~~
93
93
  $ tudu add hoge
@@ -97,13 +97,25 @@ $ tudu doings
97
97
  hoge
98
98
  ~~~
99
99
 
100
- ### done task from doing to done and from first todos to doing
100
+ * choose
101
+
102
+ ### choose no args. from first todo to doing
103
+ ~~~
104
+ $ tudu add hoge hige
105
+ $ tudu choose
106
+ $ tudu todos
107
+ hige
108
+ $ tudu doings
109
+ hoge
110
+ ~~~
111
+
112
+ ### done. from doing to done and from first todos to doing
101
113
  * done
102
114
 
103
115
  ~~~
104
116
  $ tudu add one two three
105
117
  $ tudu choose one
106
- $ done
118
+ $ tudu done
107
119
  $ tudu todos
108
120
  three
109
121
  $ tudu doings
@@ -112,13 +124,29 @@ $ tudu done
112
124
  one
113
125
  ~~~
114
126
 
127
+ ### done. from doing to done and from first todos to doing. after, if there is no todos, show celebration message.
128
+ * done
129
+
130
+ ~~~
131
+ $ tudu add one two
132
+ $ tudu choose one
133
+ $ tudu done
134
+ $ tudu done
135
+ All Tasks Finish!!
136
+ $ tudu todos
137
+ $ tudu doings
138
+ $ tudu done
139
+ one
140
+ two
141
+ ~~~
142
+
115
143
  ### tasks show all tasks from [todos, doings, dones].
116
144
  * tudu tasks
117
145
 
118
146
  ~~~
119
147
  $ tudu add one two three
120
148
  $ tudu choose one
121
- $ done
149
+ $ tudu done
122
150
  $ tudu tasks
123
151
  three
124
152
  two
@@ -185,6 +213,8 @@ if you want to do other operation, edit [todos, doings, dones] directly.
185
213
  it's only plain text, so you can edit freely.
186
214
 
187
215
  ## History
216
+ * version 0.0.2 : after execute 'done', if there is no todos and doings, display celebration message.
217
+ * version 0.0.2 : if 'choose' no args. choose first tudu.
188
218
  * version 0.0.1 : first release.
189
219
 
190
220
  ## Contributing
data/lib/tasks.rb CHANGED
@@ -1,281 +1,289 @@
1
- # encoding: utf-8
2
-
3
- module Tudu
4
- #= Tudu::Tasks
5
- class Tasks
6
- #== Tudufile key
7
- TUDU_FILE_KEY = :tudufile
8
- #== todo key
9
- TUDU_TODO_KEY = :todo
10
- #== doing key
11
- TUDU_DOING_KEY = :doing
12
- #== done key
13
- TUDU_DONE_KEY = :done
14
- #== file's key
15
- TUDU_KEYS = [TUDU_FILE_KEY, TUDU_TODO_KEY, TUDU_DOING_KEY, TUDU_DONE_KEY]
16
-
17
- #== Tudufile file name
18
- TUDU_FILE = "Tudufile"
19
- #== Tudufile file name
20
- TUDU_DIR = "tudu"
21
- #== todo file name
22
- TUDU_TODOS_FILE = "todos"
23
- #== todo file path
24
- TUDU_TODOS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_TODOS_FILE}"
25
- #== doing file name
26
- TUDU_DOINGS_FILE = "doings"
27
- #== doing file path
28
- TUDU_DOINGS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DOINGS_FILE}"
29
- #== done file name
30
- TUDU_DONES_FILE = "dones"
31
- #== done file path
32
- TUDU_DONES_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DONES_FILE}"
33
- #== file names
34
- INIT_FILES = {
35
- TUDU_FILE_KEY => TUDU_FILE,
36
- TUDU_TODO_KEY => TUDU_TODOS_FILE,
37
- TUDU_DOING_KEY => TUDU_DOINGS_FILE,
38
- TUDU_DONE_KEY => TUDU_DONES_FILE
39
- }
40
- #== task file names
41
- TASK_FILES = {
42
- TUDU_TODO_KEY => TUDU_TODOS_FILE,
43
- TUDU_DOING_KEY => TUDU_DOINGS_FILE,
44
- TUDU_DONE_KEY => TUDU_DONES_FILE
45
- }
46
-
47
- #== Tudufile file template
48
- TUDU_FILE_TEMPLATE =<<-EOS
49
- # encoding: utf-8
50
-
51
- # !!!!!!! in tudu ver 0.0.1 this file not using !!!!!!!
52
-
53
- # if you want to use notification, set target type. default => :none
54
- # you can set :none, :mail
55
- # target_type :mail
56
-
57
- # if you want to use notification, set targets. default => []
58
- # if you choose target_type none, you must not set targets.
59
- # if you choose mail, you must set target email addresses.
60
- # targets ["target1@abcdefg", "target2@abcdefg"]
61
- EOS
62
-
63
- #== todo file template
64
- TUDU_TODOS_FILE_TEMPLATE = ""
65
- #== doing file template
66
- TUDU_DOINGS_FILE_TEMPLATE = ""
67
- #== done file template
68
- TUDU_DONES_FILE_TEMPLATE = ""
69
-
70
- #== template files
71
- INIT_FILES_TEMPLATE = {
72
- TUDU_FILE_KEY => TUDU_FILE_TEMPLATE,
73
- TUDU_TODO_KEY => TUDU_TODOS_FILE_TEMPLATE,
74
- TUDU_DOING_KEY => TUDU_DOINGS_FILE_TEMPLATE,
75
- TUDU_DONE_KEY => TUDU_DONES_FILE_TEMPLATE
76
- }
77
-
78
- #== task type [todo, doing, done]
79
- attr_accessor :type
80
- #== task name [uniq]
81
- attr_accessor :name
82
-
83
- class << self
84
- #== add task to todos
85
- #=== Params
86
- #- task_names : add task name list
87
- def add(*task_names)
88
- task_names.each do |task_name|
89
- if find_tasks(task_name)
90
- puts "#{task_name} is already exists."
91
- next
92
- end
93
- File.open(TUDU_TODOS_FILE_PATH, "a:UTF-8") {|f|f.puts task_name}
94
- puts "complete add todo '#{task_name}' to tudu/todos"
95
- end
96
- end
97
-
98
- #== remove task to todo
99
- #=== Params
100
- #- task_names : remove task name list
101
- def remove(*task_names)
102
- task_names.each do |task_name|
103
- can_find = false
104
- TASK_FILES.each_value do |rf|
105
- tasks = get_tasks_from_file(rf)
106
- next unless has_task?(tasks, task_name)
107
- remove_task(tasks, task_name, "./#{TUDU_DIR}/#{rf}")
108
- can_find = true
109
- break
110
- end
111
- puts "no such todo '#{task_name}'" unless can_find
112
- end
113
- end
114
-
115
- #== choose todo => doing task
116
- #=== Params
117
- #- task_name : target task name
118
- def choose(task_name)
119
- if get_doings.size > 0
120
- puts "before choose, you must done current doings."
121
- return
122
- end
123
-
124
- task = find_tasks(task_name)
125
-
126
- if task.nil?
127
- puts "#{task_name} not exists"
128
- return
129
- end
130
-
131
- unless task.todo?
132
- puts "#{task_name} is not exists in todos. #{task_name} in #{task.type}"
133
- return
134
- end
135
-
136
- remove task_name
137
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts task_name}
138
- puts "complete add doings '#{task_name}'"
139
- end
140
-
141
- #== doing to done
142
- #- if doings size == 0, nothing todo.
143
- #- after move doing to done, next todo move to doing.
144
- def done
145
- return unless doings_to_dones
146
- todos_to_doings
147
- end
148
-
149
- #== get todos type tasks.
150
- #=== Returns
151
- # return Array[Tasks]
152
- def get_todos
153
- get_tasks(TUDU_TODOS_FILE)
154
- end
155
-
156
- #== get doings type tasks.
157
- #=== Returns
158
- # return Array[Tasks]
159
- def get_doings
160
- get_tasks(TUDU_DOINGS_FILE)
161
- end
162
-
163
- #== get dones type tasks.
164
- #=== Returns
165
- # return Array[Tasks]
166
- def get_dones
167
- get_tasks(TUDU_DONES_FILE)
168
- end
169
-
170
- #== get each type tasks.
171
- #=== Params
172
- #- type : task type.if use nil, you can get all types task.
173
- #=== Returns
174
- # return Array[Tasks]
175
- def get_tasks(type = nil)
176
- type.nil? ? get_all_tasks : get_each_tasks(type)
177
- end
178
-
179
- #== get each type tasks from file.
180
- #=== Params
181
- #- type : task type.
182
- #=== Returns
183
- # return Array[String]
184
- def get_tasks_from_file(file_name)
185
- File.read("./#{TUDU_DIR}/#{file_name}").split("\n")
186
- end
187
-
188
- #== filter tasklist by search_word.
189
- #=== Params
190
- #- tasks : task list.
191
- #- search_word : filtering word.
192
- #=== Returns
193
- # return filterd task list
194
- def filter_tasks(tasks, search_word)
195
- return tasks if search_word.nil?
196
- tasks.select {|task|task.name.match /.*#{search_word}.*/}
197
- end
198
-
199
- #== find task from all tasks.
200
- #=== Params
201
- #- task_name : task name.
202
- #=== Returns
203
- # return task
204
- def find_tasks(task_name)
205
- tasks = get_tasks
206
- tasks.select {|task|task.name == task_name}.first
207
- end
208
-
209
- private
210
- def get_each_tasks(type)
211
- tasks = []
212
- get_tasks_from_file(type).each {|task|tasks << Tasks.new(type, task)}
213
- tasks
214
- end
215
-
216
- def get_all_tasks
217
- tasks = []
218
- TASK_FILES.each_value {|each_type|tasks += get_each_tasks(each_type)}
219
- tasks
220
- end
221
-
222
- def has_task?(tasks, task_name)
223
- tasks.include? task_name
224
- end
225
-
226
- def remove_task(tasks, task_name, file_path)
227
- tasks.delete(task_name)
228
- File.open(file_path, "w:UTF-8") {|wf|wf.puts tasks.join("\n")}
229
- puts "complete remove todo '#{task_name}' from #{file_path}"
230
- end
231
-
232
- def doings_to_dones
233
- _doings = get_doings
234
- if _doings.size == 0
235
- puts "there is no doing task.before done, you must choose task."
236
- return false
237
- end
238
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.print ""}
239
- File.open(TUDU_DONES_FILE_PATH, "a:UTF-8") {|f|f.puts _doings.first.name}
240
- true
241
- end
242
-
243
- def todos_to_doings
244
- _todos = get_todos
245
- return if _todos.size == 0
246
- deleted_todos = _todos.dup
247
- deleted_todos.delete_at 0
248
- File.open(TUDU_TODOS_FILE_PATH, "w:UTF-8") do |f|
249
- deleted_todos.each {|task|f.puts task.name}
250
- end
251
- File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts _todos.first.name}
252
- end
253
- end
254
-
255
- #== init task with setting task type and task name.
256
- def initialize(type, name)
257
- @type, @name = type, name
258
- end
259
-
260
- def todo?
261
- @type == "todos"
262
- end
263
-
264
- def doing?
265
- @type == "doings"
266
- end
267
-
268
- def done?
269
- @type == "dones"
270
- end
271
-
272
- def ==(other)
273
- if self.name == other.name
274
- if self.type == other.type
275
- return true
276
- end
277
- end
278
- false
279
- end
280
- end
281
- end
1
+ # encoding: utf-8
2
+
3
+ module Tudu
4
+ #= Tudu::Tasks
5
+ class Tasks
6
+ #== Tudufile key
7
+ TUDU_FILE_KEY = :tudufile
8
+ #== todo key
9
+ TUDU_TODO_KEY = :todo
10
+ #== doing key
11
+ TUDU_DOING_KEY = :doing
12
+ #== done key
13
+ TUDU_DONE_KEY = :done
14
+ #== file's key
15
+ TUDU_KEYS = [TUDU_FILE_KEY, TUDU_TODO_KEY, TUDU_DOING_KEY, TUDU_DONE_KEY]
16
+
17
+ #== Tudufile file name
18
+ TUDU_FILE = "Tudufile"
19
+ #== Tudufile file name
20
+ TUDU_DIR = "tudu"
21
+ #== todo file name
22
+ TUDU_TODOS_FILE = "todos"
23
+ #== todo file path
24
+ TUDU_TODOS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_TODOS_FILE}"
25
+ #== doing file name
26
+ TUDU_DOINGS_FILE = "doings"
27
+ #== doing file path
28
+ TUDU_DOINGS_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DOINGS_FILE}"
29
+ #== done file name
30
+ TUDU_DONES_FILE = "dones"
31
+ #== done file path
32
+ TUDU_DONES_FILE_PATH = "./#{TUDU_DIR}/#{TUDU_DONES_FILE}"
33
+ #== file names
34
+ INIT_FILES = {
35
+ TUDU_FILE_KEY => TUDU_FILE,
36
+ TUDU_TODO_KEY => TUDU_TODOS_FILE,
37
+ TUDU_DOING_KEY => TUDU_DOINGS_FILE,
38
+ TUDU_DONE_KEY => TUDU_DONES_FILE
39
+ }
40
+ #== task file names
41
+ TASK_FILES = {
42
+ TUDU_TODO_KEY => TUDU_TODOS_FILE,
43
+ TUDU_DOING_KEY => TUDU_DOINGS_FILE,
44
+ TUDU_DONE_KEY => TUDU_DONES_FILE
45
+ }
46
+
47
+ #== Tudufile file template
48
+ TUDU_FILE_TEMPLATE =<<-EOS
49
+ # encoding: utf-8
50
+
51
+ # !!!!!!! in tudu ver 0.0.1 this file not using !!!!!!!
52
+
53
+ # if you want to use notification, set target type. default => :none
54
+ # you can set :none, :mail
55
+ # target_type :mail
56
+
57
+ # if you want to use notification, set targets. default => []
58
+ # if you choose target_type none, you must not set targets.
59
+ # if you choose mail, you must set target email addresses.
60
+ # targets ["target1@abcdefg", "target2@abcdefg"]
61
+ EOS
62
+
63
+ #== todo file template
64
+ TUDU_TODOS_FILE_TEMPLATE = ""
65
+ #== doing file template
66
+ TUDU_DOINGS_FILE_TEMPLATE = ""
67
+ #== done file template
68
+ TUDU_DONES_FILE_TEMPLATE = ""
69
+
70
+ #== template files
71
+ INIT_FILES_TEMPLATE = {
72
+ TUDU_FILE_KEY => TUDU_FILE_TEMPLATE,
73
+ TUDU_TODO_KEY => TUDU_TODOS_FILE_TEMPLATE,
74
+ TUDU_DOING_KEY => TUDU_DOINGS_FILE_TEMPLATE,
75
+ TUDU_DONE_KEY => TUDU_DONES_FILE_TEMPLATE
76
+ }
77
+
78
+ #== task type [todo, doing, done]
79
+ attr_accessor :type
80
+ #== task name [uniq]
81
+ attr_accessor :name
82
+
83
+ class << self
84
+ #== add task to todos
85
+ #=== Params
86
+ #- task_names : add task name list
87
+ def add(*task_names)
88
+ task_names.each do |task_name|
89
+ if find_tasks(task_name)
90
+ puts "#{task_name} is already exists.";
91
+ next
92
+ end
93
+ File.open(TUDU_TODOS_FILE_PATH, "a:UTF-8") {|f|f.puts task_name}
94
+ puts "complete add todo '#{task_name}' to tudu/todos"
95
+ end
96
+ end
97
+
98
+ #== remove task to todo
99
+ #=== Params
100
+ #- task_names : remove task name list
101
+ def remove(*task_names)
102
+ task_names.each do |task_name|
103
+ can_find = false
104
+ TASK_FILES.each_value do |rf|
105
+ tasks = get_tasks_from_file(rf)
106
+ next unless has_task?(tasks, task_name)
107
+ remove_task(tasks, task_name, "./#{TUDU_DIR}/#{rf}")
108
+ can_find = true
109
+ break
110
+ end
111
+ puts "no such todo '#{task_name}'" unless can_find
112
+ end
113
+ end
114
+
115
+ #== choose todo => doing task
116
+ #=== Params
117
+ #- task_name : target task name
118
+ def choose(task_name)
119
+ if get_todos.size == 0
120
+ puts "todos is empty."
121
+ return
122
+ end
123
+ if get_doings.size > 0
124
+ puts "before choose, you must done current doings."
125
+ return
126
+ end
127
+ task_name = get_first_todo_name_if_nil_or_empty task_name
128
+ task = find_tasks(task_name)
129
+ if task.nil?
130
+ puts "#{task_name} not exists"
131
+ return
132
+ end
133
+ unless task.todo?
134
+ puts "#{task_name} is not exists in todos. #{task_name} in #{task.type}"
135
+ return
136
+ end
137
+ remove task_name
138
+ File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts task_name}
139
+ puts "complete add doings '#{task_name}'"
140
+ end
141
+
142
+ #== doing to done
143
+ #- if doings size == 0, nothing todo.
144
+ #- after move doing to done, next todo move to doing.
145
+ def done
146
+ return unless doings_to_dones
147
+ todos_to_doings
148
+ end
149
+
150
+ #== get todos type tasks.
151
+ #=== Returns
152
+ # return Array[Tasks]
153
+ def get_todos
154
+ get_tasks(TUDU_TODOS_FILE)
155
+ end
156
+
157
+ #== get doings type tasks.
158
+ #=== Returns
159
+ # return Array[Tasks]
160
+ def get_doings
161
+ get_tasks(TUDU_DOINGS_FILE)
162
+ end
163
+
164
+ #== get dones type tasks.
165
+ #=== Returns
166
+ # return Array[Tasks]
167
+ def get_dones
168
+ get_tasks(TUDU_DONES_FILE)
169
+ end
170
+
171
+ #== get each type tasks.
172
+ #=== Params
173
+ #- type : task type.if use nil, you can get all types task.
174
+ #=== Returns
175
+ # return Array[Tasks]
176
+ def get_tasks(type = nil)
177
+ type.nil? ? get_all_tasks : get_each_tasks(type)
178
+ end
179
+
180
+ #== get each type tasks from file.
181
+ #=== Params
182
+ #- type : task type.
183
+ #=== Returns
184
+ # return Array[String]
185
+ def get_tasks_from_file(file_name)
186
+ File.read("./#{TUDU_DIR}/#{file_name}").split("\n")
187
+ end
188
+
189
+ #== filter tasklist by search_word.
190
+ #=== Params
191
+ #- tasks : task list.
192
+ #- search_word : filtering word.
193
+ #=== Returns
194
+ # return filterd task list
195
+ def filter_tasks(tasks, search_word)
196
+ return tasks if search_word.nil?
197
+ tasks.select {|task|task.name.match /.*#{search_word}.*/}
198
+ end
199
+
200
+ #== find task from all tasks.
201
+ #=== Params
202
+ #- task_name : task name.
203
+ #=== Returns
204
+ # return task
205
+ def find_tasks(task_name)
206
+ tasks = get_tasks
207
+ tasks.select {|task|task.name == task_name}.first
208
+ end
209
+
210
+ private
211
+ def get_first_todo_name_if_nil_or_empty(task_name)
212
+ (task_name.nil? || task_name.empty?) ? get_todos.first.name : task_name
213
+ end
214
+
215
+ def get_each_tasks(type)
216
+ tasks = []
217
+ get_tasks_from_file(type).each {|task|tasks << Tasks.new(type, task)}
218
+ tasks
219
+ end
220
+
221
+ def get_all_tasks
222
+ tasks = []
223
+ TASK_FILES.each_value {|each_type|tasks += get_each_tasks(each_type)}
224
+ tasks
225
+ end
226
+
227
+ def has_task?(tasks, task_name)
228
+ tasks.include? task_name
229
+ end
230
+
231
+ def remove_task(tasks, task_name, file_path)
232
+ tasks.delete(task_name)
233
+ contents = tasks.size == 0 ? "" : tasks.join("\n") + "\n"
234
+ File.open(file_path, "w:UTF-8") {|wf|wf.print contents}
235
+ puts "complete remove todo '#{task_name}' from #{file_path}"
236
+ end
237
+
238
+ def doings_to_dones
239
+ _doings = get_doings
240
+ if _doings.size == 0
241
+ puts "there is no doing task.before done, you must choose task."
242
+ return false
243
+ end
244
+ File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.print ""}
245
+ File.open(TUDU_DONES_FILE_PATH, "a:UTF-8") {|f|f.puts _doings.first.name}
246
+ true
247
+ end
248
+
249
+ def todos_to_doings
250
+ _todos = get_todos
251
+ if _todos.size == 0
252
+ puts "All Tasks Finish!!" if get_doings.size == 0
253
+ return
254
+ end
255
+
256
+ deleted_todos = _todos.dup
257
+ deleted_todos.delete_at 0
258
+ File.open(TUDU_TODOS_FILE_PATH, "w:UTF-8") do |f|
259
+ deleted_todos.each {|task|f.puts task.name}
260
+ end
261
+ File.open(TUDU_DOINGS_FILE_PATH, "w:UTF-8") {|f|f.puts _todos.first.name}
262
+ end
263
+ end
264
+
265
+ #== init task with setting task type and task name.
266
+ def initialize(type, name)
267
+ @type, @name = type, name
268
+ end
269
+
270
+ def todo?
271
+ @type == "todos"
272
+ end
273
+
274
+ def doing?
275
+ @type == "doings"
276
+ end
277
+
278
+ def done?
279
+ @type == "dones"
280
+ end
281
+
282
+ def ==(other)
283
+ if self.name == other.name
284
+ return true if self.type == other.type
285
+ end
286
+ false
287
+ end
288
+ end
289
+ end
data/lib/tudu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tudu
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end