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

Class Method Details

.announce_clear(task) ⇒ Object

Announces that either a task or all tasks have had fulfillment cleared.

Parameters:

  • task (String)

    Name of task to be 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.

Parameters:

  • task (String)

    Name of task to be deleted

  • description (String)

    Description of task (optional)



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.

Parameters:

  • old_task (String)

    Name of current context

  • old_time (String)

    Time spent since starting old_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.

Parameters:

  • task (String)

    Name of task to be added



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.

Parameters:

  • task (String)

    Name of task to switch to

  • old_task (String)

    Name of current context, before switching

  • old_time (String)

    Time spent since starting old_task



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

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

Prints info for a specific task if provided. If not, prints out every description for tasks that have one.

Parameters:

  • tasklist (Hash)

    Hash of task_name => task_object pairs

  • task (String)

    Name of specific task to print info for.



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

Prints out task list and current context, if applicable.

Parameters:

  • tasklist (Hash)

    Hash of task_name => task_object pairs

  • context (String)

    Name of current task context

  • time (String)

    Elapsed time since starting current task.



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

Prints out the VERSION constant



68
69
70
# File 'lib/day/presenter.rb', line 68

def print_version
  puts "Day.rb v#{VERSION}"
end