module TodoHelper

This module provides helper methods to display the information of the TodoList instance to the user.

Public Instance Methods

_display_done_todos(todos_list) click to toggle source
# File lib/helpers/todo_helper.rb, line 25
def _display_done_todos(todos_list)
  todos_list.each do |todo|
    puts "*  ~~#{todo.description}~~"
  end
end
_display_no_matches() click to toggle source
# File lib/helpers/todo_helper.rb, line 54
def _display_no_matches
  puts 'No matches'
end
_display_todos(todos_list) click to toggle source
# File lib/helpers/todo_helper.rb, line 31
def _display_todos(todos_list)
  puts 'ID Description'
  puts '-- -----------'
  todos_list.each_with_index do |todo, idx|
    puts "#{_two_characters_format(idx + 1)} #{todo.description}"
  end
end
_display_todos_count_message(todos_list) click to toggle source
# File lib/helpers/todo_helper.rb, line 39
def _display_todos_count_message(todos_list)
  todos_count = todos_list.length
  if todos_count > 1
    puts "\n#{todos_count} tasks."
  else
    puts "\n#{todos_count} task."
  end
end
_two_characters_format(number) click to toggle source
# File lib/helpers/todo_helper.rb, line 48
def _two_characters_format(number)
  return number.to_s if number > 9

  "#{number} "
end
display_all_todos(undone:, done:) click to toggle source
# File lib/helpers/todo_helper.rb, line 6
def display_all_todos(undone:, done:)
  if undone.any? || done.any?
    _display_todos(undone)
    _display_done_todos(done)
    _display_todos_count_message(undone)
  else
    _display_no_matches
  end
end
display_undone_todos(todos_list) click to toggle source
# File lib/helpers/todo_helper.rb, line 16
def display_undone_todos(todos_list)
  if todos_list.any?
    _display_todos(todos_list)
    _display_todos_count_message(todos_list)
  else
    _display_no_matches
  end
end