Module: TaskReport
- Defined in:
- lib/task_report.rb,
lib/task_report/gist.rb,
lib/task_report/task.rb,
lib/task_report/user.rb,
lib/task_report/report.rb,
lib/task_report/duration.rb
Defined Under Namespace
Modules: Gist, User
Classes: Duration, Report, Task
Class Method Summary
collapse
Class Method Details
.continue(task_id) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/task_report.rb', line 56
def continue(task_id)
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
@report.continue(task_id)
@report.save_to_gist!
rescue Report::TaskAlreadyOngoing, Task::TaskOngoing => e
puts "Task already underway - #{e.message}"
end
|
.current ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/task_report.rb', line 92
def current
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
@report.print_current_task
rescue Report::MultipleOngoingTasks
puts 'Something went wrong. There are multiple ongoing tasks.'
end
|
.delete(identifier) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/task_report.rb', line 71
def delete(identifier)
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
case identifier
when 'today'
@report.delete_all
when 'gist'
puts "Deleting today's report gist"
Gist.delete(@report.gist_id)
return
else
@report.delete(identifier)
end
@report.save_to_gist!
rescue Report::TaskDNE
puts "Task '#{identifier}' does not exist - nothing to do."
end
|
.list ⇒ Object
66
67
68
69
|
# File 'lib/task_report.rb', line 66
def list
return if no_gist?
(@report || Report.create_from_gist(report_gist)).print_tasks
end
|
.note(task_id, note) ⇒ Object
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/task_report.rb', line 138
def note(task_id, note)
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
@report.add_note(task_id, note)
@report.save_to_gist!
rescue Report::TaskDNE
puts "Task '#{identifier}' does not exist - nothing to do."
end
|
.print_range_summary_to_gist(reports, from, to) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/task_report.rb', line 117
def print_range_summary_to_gist(reports, from, to)
content = reports.map { |r| r.gist_summary_content }.compact.join("\n\n")
file_name = "task_report_#{from}_-_#{to}.md"
gist =
Gist.create_or_update(
{
public: false,
description: "Task Report: #{from} - #{to}",
files: {
file_name => {
content: content
}
}
},
Time.parse(from)
)
puts gist['html_url']
end
|
.read_config ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/task_report.rb', line 10
def read_config
config_path = File.expand_path('~/.task_report_config')
config = YAML.load(File.read(config_path))
TaskReport::User.name = config.fetch('user')
TaskReport::User.api_token = config.fetch('personal_access_token')
rescue Errno::ENOENT
puts 'Config file not found. It should be located at ~/.task_report_config.'
puts 'See https://github.com/mpataki/task_report for help.'
puts 'Exiting'
exit 1
rescue Psych::SyntaxError
puts 'The config file must be valid yaml syntax.'
puts 'Exiting'
exit 1
rescue KeyError
puts 'Config key not found.'
puts 'Required configuration keys are `user` and `personal_access_token`'
puts 'See an example at https://github.com/mpataki/task_report'
puts 'Exiting'
exit 1
end
|
.start(new_task_description) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/task_report.rb', line 32
def start(new_task_description)
if report_gist.nil?
@report ||= Report.create(new_task_description: new_task_description)
else
@report ||= Report.create_from_gist(report_gist)
@report.stop_all_tasks
end
@report.start_task(new_task_description)
@report.save_to_gist!
rescue Report::TaskAlreadyTracked
puts "Task '#{new_task_description}' is already being tracked. Continuing the task."
continue(new_task_description)
end
|
.stop ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/task_report.rb', line 47
def stop
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
@report.stop_all_tasks
@report.save_to_gist!
puts "All tasks stopped"
end
|
.summary(gist, from, to) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/task_report.rb', line 101
def summary(gist, from, to)
if from
return range_summary(gist, from, to || Time.now.strftime('%Y-%m-%d'))
end
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
if gist
@report.gist_summary
else
@report.print_summary
end
end
|
.total ⇒ Object
149
150
151
152
153
154
|
# File 'lib/task_report.rb', line 149
def total
return if no_gist?
@report ||= Report.create_from_gist(report_gist)
@report.total
end
|