Module: RubyTodo::DisplayFormatter

Included in:
CLI
Defined in:
lib/ruby_todo/formatters/display_formatter.rb

Instance Method Summary collapse

Instance Method Details

#display_tasks(tasks) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ruby_todo/formatters/display_formatter.rb', line 46

def display_tasks(tasks)
  if ENV["RUBY_TODO_TEST"]
    display_tasks_simple_format(tasks)
  else
    display_tasks_table_format(tasks)
  end
end

#format_due_date(due_date) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby_todo/formatters/display_formatter.rb', line 26

def format_due_date(due_date)
  return "No due date" unless due_date

  if due_date < Time.now && due_date > Time.now - 24 * 60 * 60
    "Today #{due_date.strftime("%H:%M")}".red
  elsif due_date < Time.now
    "Overdue #{due_date.strftime("%Y-%m-%d %H:%M")}".red
  elsif due_date < Time.now + 24 * 60 * 60
    "Today #{due_date.strftime("%H:%M")}".yellow
  else
    due_date.strftime("%Y-%m-%d %H:%M")
  end
end

#format_priority(priority) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_todo/formatters/display_formatter.rb', line 15

def format_priority(priority)
  return nil unless priority

  case priority.downcase
  when "high" then "High".red
  when "medium" then "Medium".yellow
  when "low" then "Low".green
  else priority
  end
end

#format_status(status) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/ruby_todo/formatters/display_formatter.rb', line 5

def format_status(status)
  case status
  when "todo" then "Todo".yellow
  when "in_progress" then "In Progress".blue
  when "done" then "Done".green
  when "archived" then "Archived".gray
  else status
  end
end

#truncate_text(text, length = 30) ⇒ Object



40
41
42
43
44
# File 'lib/ruby_todo/formatters/display_formatter.rb', line 40

def truncate_text(text, length = 30)
  return nil unless text

  text.length > length ? "#{text[0...length]}..." : text
end