Module: Presenter
- Defined in:
- lib/day/presenter.rb
Overview
DayRB Presentation Module
Handles printouts and error messages. Also adds colorization as specified in main file.
MIT License; See LICENSE file; Cameron Carroll 2014
Class Method Summary collapse
-
.announce_clear(task) ⇒ Object
Announces that either a task or all tasks have had fulfillment cleared.
-
.announce_deletion(task, description) ⇒ Object
Announces task has been deleted and prints its description if applicable.
-
.announce_leave_context(old_task, old_time) ⇒ Object
Announces that we leave current context, prints out time spent.
-
.announce_new_task(task) ⇒ Object
Announces the creation of a new task.
-
.announce_switch(task, old_task, old_time) ⇒ Object
Announces a switch to a new task…
-
.print_help ⇒ Object
Prints out program help string.
-
.print_info(tasklist, task) ⇒ Object
Prints info for a specific task if provided.
-
.print_list(tasklist, context, time) ⇒ Object
Prints out task list and current context, if applicable.
-
.print_version ⇒ Object
Prints out the VERSION constant.
Class Method Details
.announce_clear(task) ⇒ Object
Announces that either a task or all tasks have had fulfillment cleared.
84 85 86 87 88 89 90 |
# File 'lib/day/presenter.rb', line 84 def announce_clear(task) if task puts "Cleared fulfillment for #{task}".color_text else puts "Cleared fulfillment for all tasks".color_text end end |
.announce_deletion(task, description) ⇒ Object
Announces task has been deleted and prints its description if applicable.
76 77 78 79 |
# File 'lib/day/presenter.rb', line 76 def announce_deletion(task, description) puts "Deleted #{task}".color_text puts "Description was: #{description}".color_text if description end |
.announce_leave_context(old_task, old_time) ⇒ Object
Announces that we leave current context, prints out time spent. Used when not starting a new task.
110 111 112 113 |
# File 'lib/day/presenter.rb', line 110 def announce_leave_context(old_task, old_time) puts "Stopping tracking for #{old_task}" puts "(Spent #{convert_time_with_suffix old_time})" end |
.announce_new_task(task) ⇒ Object
Announces the creation of a new task.
118 119 120 |
# File 'lib/day/presenter.rb', line 118 def announce_new_task(task) puts "Added new task, #{task}" end |
.announce_switch(task, old_task, old_time) ⇒ Object
Announces a switch to a new task… also prints the amount of time spent on the old one.
98 99 100 101 102 103 |
# File 'lib/day/presenter.rb', line 98 def announce_switch(task, old_task, old_time) puts "Switching to #{task}" if old_task && old_time puts "(Spent #{convert_time_with_suffix old_time} on #{old_task})" end end |
.print_help ⇒ Object
Prints out program help string
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/day/presenter.rb', line 48 def print_help puts <<-eos Usage: day.rb <command> [<args>] Commands: (no command) Prints out task list for the day (nonexisting task) Creates a new task (existing task) Start tracking time for named task. delete (task) Remove a task info Print all descriptions info (task) Print a specific description clear Clear fulfillment for all tasks. clear (task) Clear fulfillment for a specific task. Refer to a task either by its name or index. See readme.md for a more detailed overview. eos end |
.print_info(tasklist, task) ⇒ Object
Prints info for a specific task if provided. If not, prints out every description for tasks that have one.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/day/presenter.rb', line 32 def print_info(tasklist, task) if task task_object = tasklist[task] if task_object.description print_description task, task_object else puts "There was no description for #{task}." end else tasklist.each do |task_name, task_object| print_description task_name, task_object if task_object.description end end end |
.print_list(tasklist, context, time) ⇒ Object
Prints out task list and current context, if applicable.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/day/presenter.rb', line 16 def print_list(tasklist, context, time) if tasklist.empty? print_error_empty else print_task_list(tasklist) end if context print_current_context(context, time) end end |
.print_version ⇒ Object
Prints out the VERSION constant
68 69 70 |
# File 'lib/day/presenter.rb', line 68 def print_version puts "Day.rb v#{VERSION}" end |