Class: Medo::TextTaskWriter
- Inherits:
-
TaskWriter
- Object
- TaskWriter
- Medo::TextTaskWriter
- Defined in:
- lib/medo/text_task_writer.rb,
lib/medo/text_task_writer/decorators/colors_decorator.rb,
lib/medo/text_task_writer/decorators/numbers_decorator.rb
Defined Under Namespace
Modules: Decorators Classes: TaskPresenter
Instance Method Summary collapse
-
#initialize(output_stream = STDOUT) ⇒ TextTaskWriter
constructor
A new instance of TextTaskWriter.
- #write ⇒ Object
Methods inherited from TaskWriter
Constructor Details
#initialize(output_stream = STDOUT) ⇒ TextTaskWriter
Returns a new instance of TextTaskWriter.
6 7 8 9 |
# File 'lib/medo/text_task_writer.rb', line 6 def initialize(output_stream = STDOUT) super() @output_stream = output_stream end |
Instance Method Details
#write ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/medo/text_task_writer.rb', line 11 def write return puts "There are no tasks left!" if @tasks.empty? presented_active_tasks = present_tasks(active_tasks) presented_completed_tasks = present_tasks(completed_tasks) max_task_length = (presented_active_tasks + presented_completed_tasks).map do |t| t.to_s.split("\n").map(&:size).max end.max max_output_width = [Terminal.instance.size.first, max_task_length].min presented_active_tasks.each do |t| @output_stream.puts t.to_s(max_output_width) end if presented_active_tasks.any? and presented_completed_tasks.any? @output_stream.puts "-" * max_output_width end presented_completed_tasks.each do |t| @output_stream.puts t.to_s(max_output_width) end end |