Class: Medo::TextTaskWriter::TaskPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/medo/text_task_writer.rb

Defined Under Namespace

Classes: Components

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ TaskPresenter

Returns a new instance of TaskPresenter.



54
55
56
# File 'lib/medo/text_task_writer.rb', line 54

def initialize(task)
  @task = task
end

Instance Method Details

#description(length = nil, options = {}) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/medo/text_task_writer.rb', line 58

def description(length = nil, options = {})
  if length
    break_line_to_fit(@task.description, length, options)
  else
    @task.description
  end
end

#doneObject



86
87
88
# File 'lib/medo/text_task_writer.rb', line 86

def done
  "[#{@task.done? ? '+' : ' '}]"
end

#notes(length = nil, options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/medo/text_task_writer.rb', line 75

def notes(length = nil, options = {})
  return "" if @task.notes.empty?
  "\n\n" + @task.notes.map do |n|
    if length
      break_line_to_fit(n, length, options)
    else
      n.rjust(n.size + done.size + 1)
    end
  end.join("\n") + "\n\n"
end

#timeObject



66
67
68
69
70
71
72
73
# File 'lib/medo/text_task_writer.rb', line 66

def time
  format = "%H:%M"
  if @task.done?
    "[#{@task.completed_at.strftime(format)}]"
  else
    "(#{@task.created_at.strftime(format)})"
  end
end

#to_s(length = nil) ⇒ Object



90
91
92
93
# File 'lib/medo/text_task_writer.rb', line 90

def to_s(length = nil)
  c = components(length)
  "#{c.done} #{c.description} #{c.time}#{c.notes}"
end