module Main
This module decides which flow to initiate depending on the first argument (add, list, etc)
Public Instance Methods
handle_add(description)
click to toggle source
# File lib/main.rb, line 33 def handle_add(description) if description.empty? WarningHelper.print_add_description_is_required else todos_controller.add_todo description.join(' ') end end
handle_delete(index)
click to toggle source
# File lib/main.rb, line 59 def handle_delete(index) return WarningHelper.print_task_index_is_required if index.nil? if index.to_i <= 0 return WarningHelper.print_task_index_not_positive_integer end todos_controller.delete_todo index.to_i end
handle_done(index)
click to toggle source
# File lib/main.rb, line 50 def handle_done(index) return WarningHelper.print_task_index_is_required if index.nil? if index.to_i <= 0 return WarningHelper.print_task_index_not_positive_integer end todos_controller.complete_todo index.to_i end
handle_list(flag)
click to toggle source
# File lib/main.rb, line 41 def handle_list(flag) case flag when nil then todos_controller.list_pending_todos when '--all' then todos_controller.list_all_todos else WarningHelper.print_flag_not_recognized(flag) end end
process_argv(arguments)
click to toggle source
# File lib/main.rb, line 14 def process_argv(arguments) method, *parameters = arguments case method when 'add' then handle_add parameters when 'list' then handle_list parameters[0] when 'done' then handle_done parameters[0] when 'delete' then handle_delete parameters[0] when nil then WarningHelper.print_method_is_required else # TODO: create --help, -h option/flag WarningHelper.print_command_not_recognized_or_missing method end end
todos_controller()
click to toggle source
# File lib/main.rb, line 29 def todos_controller TodosController.new end