class TodoList::CommandLineInterface

Public Instance Methods

add() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 17
def add
  description = ARGV[1..-1].join(" ")

  @task_list << Task.new(description) unless description.empty?

  print_list
end
clean() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 50
def clean
  @task_list = TaskList.new(get_todo_tasks)

  print_list
end
done() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 38
def done
  get_todo_tasks[get_task_index].done = true

  print_list
end
edit() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 25
def edit
  task = get_todo_tasks[get_task_index]

  if ARGV.size > 2
    task.description = ARGV[2..-1].join(" ")
  else
    RbReadline.prefill_prompt(task.description)
    task.description = Readline.readline("Edit description: ")
  end

  print_list
end
help()
Alias for: print_help
print_help() click to toggle source
Also aliased as: help
print_list() click to toggle source
remove() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 44
def remove
  @task_list.delete(get_todo_tasks[get_task_index])

  print_list
end
run() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 6
def run
  command = ARGV[0]
  command ||= "print_list"

  if respond_to?(command)
    execute(command)
  else
    print_command_error(%(Unknown command #{bold(command)}.))
  end
end
wipe() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 56
def wipe
  @task_list = TaskList.new

  print_list
end

Private Instance Methods

bold(string) click to toggle source
# File lib/todo_list/command_line_interface.rb, line 127
def bold(string)
  "\033[1m#{string}\033[0m"
end
execute(command) click to toggle source
# File lib/todo_list/command_line_interface.rb, line 101
def execute(command)
  @task_list = TaskList.load(SAVE_PATH)

  send(command)

  @task_list.save(SAVE_PATH)
end
get_done_tasks() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 109
def get_done_tasks
  @task_list.select { |e| e.done? }
end
get_task_index() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 131
def get_task_index
  task_index = ARGV[1].to_i - 1

  unless task_index.between?(0, get_todo_tasks.size - 1)
    puts "Please type a valid task number."
    exit
  end

  task_index
end
get_todo_tasks() click to toggle source
# File lib/todo_list/command_line_interface.rb, line 113
def get_todo_tasks
  @task_list.select { |e| !e.done? }
end
print_command_error(error_message) click to toggle source
underline(string) click to toggle source
# File lib/todo_list/command_line_interface.rb, line 123
def underline(string)
  "\033[4m#{string}\033[0m"
end