tudu 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d854c851707b6c6e42759565ec28691f91de494
4
+ data.tar.gz: 318deac04bd2ad49d539a954320befbc7b9f0852
5
+ SHA512:
6
+ metadata.gz: d00bf36e7a0b77347a0edff5cea73990034f1a5dda492eaefe196c620d87c161266c651b62ee6a5d28d486c80ee45bca6d58f7bdd6921c5189aa55ab65ea5fe3
7
+ data.tar.gz: c3100a1d47e957d0ea42778022e6d7d00b590eff9c6e120979b40d01c7eee2f38ec759350611a54696d773ab9377e29d85e22a872dab264556bc429ba18336c4
data/.rubocop.yml CHANGED
@@ -1,4 +0,0 @@
1
- LineLength:
2
- Enabled: false
3
- ClassLength:
4
- Enabled: false
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem "rspec", "~> 2.14.1"
5
- gem "thor", "~> 0.18.1"
6
- gem "simplecov", "~> 0.8.2"
7
- gem "highline", "~> 1.6.20"
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
data/bin/tudu CHANGED
@@ -5,6 +5,7 @@ require 'tudu/version'
5
5
  require 'tudu_core'
6
6
  require 'thor'
7
7
 
8
+ # rubocop:disable LineLength
8
9
  module Tudu
9
10
  # = Tudu CLI
10
11
  class CLI < Thor
@@ -78,3 +79,4 @@ module Tudu
78
79
  end
79
80
  end
80
81
  Tudu::CLI.start(ARGV)
82
+ # rubocop:enable LineLength
data/lib/task.rb ADDED
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ module Tudu
4
+ # = Tudu::Task
5
+ class Task
6
+ # == task type [todo, doing, done]
7
+ attr_accessor :type
8
+ # == task name [uniq]
9
+ attr_accessor :name
10
+
11
+ # == init task with setting task type and task name.
12
+ def initialize(type, name)
13
+ @type, @name = type, name
14
+ end
15
+
16
+ def todo?
17
+ @type == 'todos'
18
+ end
19
+
20
+ def doing?
21
+ @type == 'doings'
22
+ end
23
+
24
+ def done?
25
+ @type == 'dones'
26
+ end
27
+
28
+ def ==(other)
29
+ return true if name == other.name && type == other.type
30
+ false
31
+ end
32
+ end
33
+ end
data/lib/tasks.rb CHANGED
@@ -1,85 +1,11 @@
1
1
  # encoding: utf-8
2
+ require 'task'
3
+ require 'tudu_file_keys'
2
4
 
5
+ # rubocop:disable ClassLength
3
6
  module Tudu
4
7
  # = Tudu::Tasks
5
8
  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
9
  class << self
84
10
  # == add task to todos
85
11
  # === Params
@@ -90,7 +16,9 @@ module Tudu
90
16
  puts "#{task_name} is already exists."
91
17
  next
92
18
  end
93
- File.open(TUDU_TODOS_FILE_PATH, 'a:UTF-8') { |f|f.puts task_name }
19
+ File.open(TuduPaths::TUDU_TODOS_FILE_PATH, 'a:UTF-8') do |f|
20
+ f.puts task_name
21
+ end
94
22
  puts "complete add todo '#{task_name}' to tudu/todos"
95
23
  end
96
24
  end
@@ -113,7 +41,7 @@ module Tudu
113
41
  return if when_choose_no_task?(task, task_name)
114
42
  return unless when_choose_type_is_todo?(task, task_name)
115
43
  remove task_name
116
- File.open(TUDU_DOINGS_FILE_PATH, 'w:UTF-8') { |f|f.puts task_name }
44
+ write_doing(task_name)
117
45
  puts "complete add doings '#{task_name}'"
118
46
  end
119
47
 
@@ -128,22 +56,22 @@ module Tudu
128
56
  # == get todos type tasks.
129
57
  # === Returns
130
58
  # return Array[Tasks]
131
- def get_todos
132
- get_tasks(TUDU_TODOS_FILE)
59
+ def todos
60
+ get_tasks(TuduPaths::TUDU_TODOS_FILE)
133
61
  end
134
62
 
135
63
  # == get doings type tasks.
136
64
  # === Returns
137
65
  # return Array[Tasks]
138
- def get_doings
139
- get_tasks(TUDU_DOINGS_FILE)
66
+ def doings
67
+ get_tasks(TuduPaths::TUDU_DOINGS_FILE)
140
68
  end
141
69
 
142
70
  # == get dones type tasks.
143
71
  # === Returns
144
72
  # return Array[Tasks]
145
- def get_dones
146
- get_tasks(TUDU_DONES_FILE)
73
+ def dones
74
+ get_tasks(TuduPaths::TUDU_DONES_FILE)
147
75
  end
148
76
 
149
77
  # == get each type tasks.
@@ -152,7 +80,7 @@ module Tudu
152
80
  # === Returns
153
81
  # return Array[Tasks]
154
82
  def get_tasks(type = nil)
155
- type.nil? ? get_all_tasks : get_each_tasks(type)
83
+ type.nil? ? all_tasks : get_each_tasks(type)
156
84
  end
157
85
 
158
86
  # == get each type tasks from file.
@@ -161,7 +89,7 @@ module Tudu
161
89
  # === Returns
162
90
  # return Array[String]
163
91
  def get_tasks_from_file(file_name)
164
- File.read("./#{TUDU_DIR}/#{file_name}").split("\n")
92
+ File.read("./#{TuduPaths::TUDU_DIR}/#{file_name}").split("\n")
165
93
  end
166
94
 
167
95
  # == filter tasklist by search_word.
@@ -172,7 +100,7 @@ module Tudu
172
100
  # return filterd task list
173
101
  def filter_tasks(tasks, search_word)
174
102
  return tasks if search_word.nil?
175
- tasks.select { |task|task.name.match /.*#{search_word}.*/ }
103
+ tasks.select { |task|task.name.match(/.*#{search_word}.*/) }
176
104
  end
177
105
 
178
106
  # == find task from all tasks.
@@ -190,8 +118,8 @@ module Tudu
190
118
  # return progress
191
119
  def progress
192
120
  total_count = get_tasks.size
193
- dones_count = get_dones.size
194
- percent = total_count == 0 ? 0 : (dones_count.to_f / total_count.to_f * 100).round
121
+ dones_count = dones.size
122
+ percent = total_count == 0 ? 0 : percentage(dones_count, total_count)
195
123
  prefix = "#{dones_count}/#{total_count}|"
196
124
  done_bar = '=' * (percent / 10)
197
125
  rest_bar = ' ' * (10 - (percent / 10))
@@ -202,32 +130,38 @@ module Tudu
202
130
 
203
131
  private
204
132
 
133
+ def percentage(base, total)
134
+ (base.to_f / total.to_f * 100).round
135
+ end
136
+
205
137
  def get_first_todo_name_if_nil_or_empty(task_name)
206
- task_name.nil? || task_name.empty? ? get_todos.first.name : task_name
138
+ task_name.nil? || task_name.empty? ? todos.first.name : task_name
207
139
  end
208
140
 
209
141
  def get_each_tasks(type)
210
142
  tasks = []
211
- get_tasks_from_file(type).each { |task|tasks << Tasks.new(type, task) }
143
+ get_tasks_from_file(type).each { |task|tasks << Task.new(type, task) }
212
144
  tasks
213
145
  end
214
146
 
215
- def get_all_tasks
147
+ def all_tasks
216
148
  tasks = []
217
- TASK_FILES.each_value { |each_type|tasks += get_each_tasks(each_type) }
149
+ TuduPaths::TASK_FILES.each_value do |each_type|
150
+ tasks += get_each_tasks(each_type)
151
+ end
218
152
  tasks
219
153
  end
220
154
 
221
- def has_task?(tasks, task_name)
155
+ def include_task?(tasks, task_name)
222
156
  tasks.include? task_name
223
157
  end
224
158
 
225
159
  def remove_each_task(task_name)
226
160
  can_find = false
227
- TASK_FILES.each_value do |rf|
161
+ TuduPaths::TASK_FILES.each_value do |rf|
228
162
  tasks = get_tasks_from_file(rf)
229
- next unless has_task?(tasks, task_name)
230
- remove_task(tasks, task_name, "./#{TUDU_DIR}/#{rf}")
163
+ next unless include_task?(tasks, task_name)
164
+ remove_task(tasks, task_name, "./#{TuduPaths::TUDU_DIR}/#{rf}")
231
165
  can_find = true
232
166
  break
233
167
  end
@@ -242,13 +176,13 @@ module Tudu
242
176
  end
243
177
 
244
178
  def when_choose_no_todos?
245
- return false unless get_todos.size == 0
179
+ return false unless todos.size == 0
246
180
  puts 'todos is empty.'
247
181
  true
248
182
  end
249
183
 
250
184
  def when_choose_no_doings?
251
- return true if get_doings.size == 0
185
+ return true if doings.size == 0
252
186
  puts 'todos is empty.'
253
187
  false
254
188
  end
@@ -261,59 +195,56 @@ module Tudu
261
195
 
262
196
  def when_choose_type_is_todo?(task, task_name)
263
197
  return true if task.todo?
264
- puts "#{task_name} is not exists in todos. #{task_name} in #{task.type}"
198
+ puts "#{task_name} is not exists in todos. #{task_name} in #{task.type}" # rubocop:disable LineLength
265
199
  false
266
200
  end
267
201
 
268
202
  def doings_to_dones
269
- _doings = get_doings
270
- if _doings.size == 0
203
+ tmp_doings = doings
204
+ if tmp_doings.size == 0
271
205
  puts 'there is no doing task.before done, you must choose task.'
272
206
  return false
273
207
  end
274
- File.open(TUDU_DOINGS_FILE_PATH, 'w:UTF-8') { |f|f.print '' }
275
- File.open(TUDU_DONES_FILE_PATH, 'a:UTF-8') { |f|f.puts _doings.first.name }
208
+ write_doing('')
209
+ write_done(tmp_doings.first.name)
276
210
  true
277
211
  end
278
212
 
213
+ def write_doing(text)
214
+ File.open(TuduPaths::TUDU_DOINGS_FILE_PATH, 'w:UTF-8') do |f|
215
+ if text.empty?
216
+ f.print(text)
217
+ else
218
+ f.puts text
219
+ end
220
+ end
221
+ end
222
+
223
+ def write_done(text)
224
+ File.open(TuduPaths::TUDU_DONES_FILE_PATH, 'a:UTF-8') do |f|
225
+ f.puts text
226
+ end
227
+ end
228
+
279
229
  def todos_to_doings
280
- _todos = get_todos
281
- return if finish?(_todos)
282
- deleted_todos = _todos.dup
230
+ tmp_todos = todos
231
+ return if finish?(tmp_todos)
232
+ deleted_todos = tmp_todos.dup
283
233
  deleted_todos.delete_at 0
284
- File.open(TUDU_TODOS_FILE_PATH, 'w:UTF-8') do |f|
234
+ File.open(TuduPaths::TUDU_TODOS_FILE_PATH, 'w:UTF-8') do |f|
285
235
  deleted_todos.each { |task|f.puts task.name }
286
236
  end
287
- File.open(TUDU_DOINGS_FILE_PATH, 'w:UTF-8') { |f|f.puts _todos.first.name }
237
+ File.open(TuduPaths::TUDU_DOINGS_FILE_PATH, 'w:UTF-8') do |f|
238
+ f.puts tmp_todos.first.name
239
+ end
288
240
  end
289
241
 
290
- def finish?(_todos)
291
- return false unless _todos.size == 0
292
- puts 'All Tasks Finish!!' if get_doings.size == 0
242
+ def finish?(tmp_todos)
243
+ return false unless tmp_todos.size == 0
244
+ puts 'All Tasks Finish!!' if doings.size == 0
293
245
  true
294
246
  end
295
247
  end
296
-
297
- # == init task with setting task type and task name.
298
- def initialize(type, name)
299
- @type, @name = type, name
300
- end
301
-
302
- def todo?
303
- @type == 'todos'
304
- end
305
-
306
- def doing?
307
- @type == 'doings'
308
- end
309
-
310
- def done?
311
- @type == 'dones'
312
- end
313
-
314
- def ==(other)
315
- return true if name == other.name && type == other.type
316
- false
317
- end
318
248
  end
319
249
  end
250
+ # rubocop:enable ClassLength
data/lib/tudu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # =TodoManage Module
3
3
  module Tudu
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
data/lib/tudu_core.rb CHANGED
@@ -2,15 +2,19 @@
2
2
  require 'tudu/version'
3
3
  require 'tasks'
4
4
  require 'highline'
5
+ require 'tudu_file_keys'
6
+ require 'tudu_paths'
5
7
 
6
8
  module Tudu
7
9
  # Tudu::Core
8
10
  class Core
9
11
  # == generate files [Tudufile, todos, doings, dones]
10
12
  def init
11
- Dir.mkdir Tudu::Tasks::TUDU_DIR unless File.exists? Tudu::Tasks::TUDU_DIR
12
- Tudu::Tasks::TUDU_KEYS.each do |key|
13
- File.open("./tudu/#{Tudu::Tasks::INIT_FILES[key]}", 'w:UTF-8') { |f|f.print Tudu::Tasks::INIT_FILES_TEMPLATE[key] }
13
+ Dir.mkdir TuduPaths::TUDU_DIR unless File.exist? TuduPaths::TUDU_DIR
14
+ TuduFileKeys::TUDU_KEYS.each do |key|
15
+ File.open("./tudu/#{TuduPaths::INIT_FILES[key]}", 'w:UTF-8') do |f|
16
+ f.print Templates::INIT_FILES_TEMPLATE[key]
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -18,28 +22,28 @@ module Tudu
18
22
  # === Params
19
23
  #- task_names : add task name list
20
24
  def add(*task_names)
21
- Tudu::Tasks.add(*task_names)
25
+ Tasks.add(*task_names)
22
26
  end
23
27
 
24
28
  # == remove task to todo
25
29
  # === Params
26
30
  #- task_names : remove task name list
27
31
  def remove(*task_names)
28
- Tudu::Tasks.remove(*task_names)
32
+ Tasks.remove(*task_names)
29
33
  end
30
34
 
31
35
  # == choose todo => doing task
32
36
  # === Params
33
37
  #- task_name : target task name
34
38
  def choose(task_name)
35
- Tudu::Tasks.choose task_name
39
+ Tasks.choose task_name
36
40
  end
37
41
 
38
42
  # == doing to done
39
43
  #- if doings size == 0, nothing todo.
40
44
  #- after move doing to done, next todo move to doing.
41
45
  def done
42
- Tudu::Tasks.done
46
+ Tasks.done
43
47
  end
44
48
 
45
49
  # == search tasks
@@ -47,12 +51,12 @@ module Tudu
47
51
  #- search_word : search word. enable regexp.
48
52
  #- options : options.
49
53
  def tasks(search_word, options)
50
- todo_list = todos search_word
51
- doing_list = doings search_word
52
- done_list = dones search_word
53
- todo_list, doing_list, done_list = coloring(options, todo_list, doing_list, done_list)
54
- categorise(options, todo_list, doing_list, done_list)
55
- todo_list + doing_list + done_list
54
+ todo_s = todos search_word
55
+ doing_s = doings search_word
56
+ done_s = dones search_word
57
+ todo_s, doing_s, done_s = coloring(options, todo_s, doing_s, done_s)
58
+ categorise(options, todo_s, doing_s, done_s)
59
+ todo_s + doing_s + done_s
56
60
  end
57
61
 
58
62
  # == search todos
@@ -80,7 +84,7 @@ module Tudu
80
84
  # === Returns
81
85
  # return progress
82
86
  def progress
83
- Tudu::Tasks.progress
87
+ Tasks.progress
84
88
  end
85
89
 
86
90
  alias_method :now, :doings
@@ -104,23 +108,23 @@ module Tudu
104
108
  end
105
109
 
106
110
  def colored?(options)
107
- !options.nil? && options[:color]
111
+ options && options[:color]
108
112
  end
109
113
 
110
114
  def categorised?(options)
111
- !options.nil? && options[:category]
115
+ options && options[:category]
112
116
  end
113
117
 
114
118
  def todos_task(search_word)
115
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_todos, search_word)
119
+ Tasks.filter_tasks(Tasks.todos, search_word)
116
120
  end
117
121
 
118
122
  def doings_task(search_word)
119
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_doings, search_word)
123
+ Tasks.filter_tasks(Tasks.doings, search_word)
120
124
  end
121
125
 
122
126
  def dones_task(search_word)
123
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_dones, search_word)
127
+ Tasks.filter_tasks(Tasks.dones, search_word)
124
128
  end
125
129
  end
126
130
  end