class TodoVoid

Public Class Methods

new(args=[], interactor = TodoInteractor.new) click to toggle source
# File lib/todo_void.rb, line 6
def initialize(args=[], interactor = TodoInteractor.new)
  @todo_interactor = interactor
  @args = args
  @output = ""
end

Public Instance Methods

execute() click to toggle source
# File lib/todo_void.rb, line 12
def execute
  if flag?('-d')
    change_status(:deleted)
  elsif flag?('-f')
    change_status(:finished)
  elsif flag?('-s')
    change_status(:started)
  elsif flag?('--help')
    @output = read_help
  elsif @args[0]
    tags = extract_tags(@args[1])
    @todo_interactor.add_todo(@args[0], tags)
  else
    todos = TodoInteractor.new.list_all
    @output = TodoListView.render(todos)
  end
  @output
end

Private Instance Methods

change_status(status) click to toggle source
# File lib/todo_void.rb, line 54
def change_status(status)
  begin
    StatusChangesInteractor.new.change_status(hash, status)
  rescue StatusChangesInteractor::NoTodoWithIdError
    @output += "There is no todo with matching id"
  rescue StatusChangesInteractor::ConflictingIdsError => e
    @output += "Conflicting part of an id provided please be more specific:\n"
    @output += TodoListView.render(e.conflicting_todos)
  end
end
extract_tags(tag_arg) click to toggle source
# File lib/todo_void.rb, line 36
def extract_tags(tag_arg)
  return [] unless tag_arg

  flag, tags = tag_arg.split("=")
  tags = tags.gsub("'", "")
  tags = tags.split(',')
  tags.map! {|tag| tag.strip}
end
flag?(flag) click to toggle source
# File lib/todo_void.rb, line 32
def flag?(flag)
  @args[0] == flag
end
hash() click to toggle source
# File lib/todo_void.rb, line 45
def hash
  @args[1]
end
read_help() click to toggle source
# File lib/todo_void.rb, line 49
def read_help
  help_template = File.join(File.dirname(__FILE__), '../templates/help')
  File.read(help_template)
end