Class: Tudu::Tasks
- Inherits:
-
Object
- Object
- Tudu::Tasks
- Defined in:
- lib/tasks.rb
Overview
Tudu::Tasks
Class Method Summary collapse
-
.add(*task_names) ⇒ Object
add task to todos === Params - task_names : add task name list.
-
.choose(task_name) ⇒ Object
choose todo => doing task === Params - task_name : target task name.
-
.doings ⇒ Object
get doings type tasks.
-
.done ⇒ Object
doing to done - if doings size == 0, nothing todo.
-
.dones ⇒ Object
get dones type tasks.
-
.filter_tasks(tasks, search_word) ⇒ Object
filter tasklist by search_word.
-
.find_tasks(task_name) ⇒ Object
find task from all tasks.
-
.get_tasks(type = nil) ⇒ Object
get each type tasks.
-
.get_tasks_from_file(file_name) ⇒ Object
get each type tasks from file.
-
.progress ⇒ Object
display tasks progress === Returns return progress.
-
.remove(*task_names) ⇒ Object
remove task to todo === Params - task_names : remove task name list.
-
.todos ⇒ Object
get todos type tasks.
Class Method Details
.add(*task_names) ⇒ Object
add task to todos
Params
-
task_names : add task name list
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tasks.rb', line 13 def add(*task_names) task_names.each do |task_name| if find_tasks(task_name) puts "#{task_name} is already exists." next end File.open(TuduPaths::TUDU_TODOS_FILE_PATH, 'a:UTF-8') do |f| f.puts task_name end puts "complete add todo '#{task_name}' to tudu/todos" end end |
.choose(task_name) ⇒ Object
choose todo => doing task
Params
-
task_name : target task name
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tasks.rb', line 36 def choose(task_name) return if when_choose_no_todos? return unless when_choose_no_doings? task_name = get_first_todo_name_if_nil_or_empty task_name task = find_tasks(task_name) return if when_choose_no_task?(task, task_name) return unless when_choose_type_is_todo?(task, task_name) remove task_name write_doing(task_name) puts "complete add doings '#{task_name}'" end |
.doings ⇒ Object
66 67 68 |
# File 'lib/tasks.rb', line 66 def doings get_tasks(TuduPaths::TUDU_DOINGS_FILE) end |
.done ⇒ Object
doing to done
-
if doings size == 0, nothing todo.
-
after move doing to done, next todo move to doing.
51 52 53 54 |
# File 'lib/tasks.rb', line 51 def done return unless doings_to_dones todos_to_doings end |
.dones ⇒ Object
73 74 75 |
# File 'lib/tasks.rb', line 73 def dones get_tasks(TuduPaths::TUDU_DONES_FILE) end |
.filter_tasks(tasks, search_word) ⇒ Object
filter tasklist by search_word.
Params
-
tasks : task list.
-
search_word : filtering word.
Returns
return filterd task list
101 102 103 104 |
# File 'lib/tasks.rb', line 101 def filter_tasks(tasks, search_word) return tasks if search_word.nil? tasks.select { |task|task.name.match(/.*#{search_word}.*/) } end |
.find_tasks(task_name) ⇒ Object
find task from all tasks.
Params
-
task_name : task name.
Returns
return task
111 112 113 114 |
# File 'lib/tasks.rb', line 111 def find_tasks(task_name) tasks = get_tasks tasks.select { |task|task.name == task_name }.first end |
.get_tasks(type = nil) ⇒ Object
get each type tasks.
Params
-
type : task type.if use nil, you can get all types task.
Returns
return Array
82 83 84 |
# File 'lib/tasks.rb', line 82 def get_tasks(type = nil) type.nil? ? all_tasks : get_each_tasks(type) end |
.get_tasks_from_file(file_name) ⇒ Object
91 92 93 |
# File 'lib/tasks.rb', line 91 def get_tasks_from_file(file_name) File.read("./#{TuduPaths::TUDU_DIR}/#{file_name}").split("\n") end |
.progress ⇒ Object
display tasks progress
Returns
return progress
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tasks.rb', line 119 def progress total_count = get_tasks.size dones_count = dones.size percent = total_count == 0 ? 0 : percentage(dones_count, total_count) prefix = "#{dones_count}/#{total_count}|" = '=' * (percent / 10) = ' ' * (10 - (percent / 10)) = "#{}>#{}" sufix = "|#{percent}%" "#{prefix}#{}#{sufix}" end |
.remove(*task_names) ⇒ Object
remove task to todo
Params
-
task_names : remove task name list
29 30 31 |
# File 'lib/tasks.rb', line 29 def remove(*task_names) task_names.each { |task_name|remove_each_task(task_name) } end |
.todos ⇒ Object
59 60 61 |
# File 'lib/tasks.rb', line 59 def todos get_tasks(TuduPaths::TUDU_TODOS_FILE) end |