Class: Topicz::Commands::ReportCommand
Instance Method Summary
collapse
#find_exactly_one_topic, #load_config, #load_repository, #process_excludes
Constructor Details
#initialize(config_file = nil, arguments = []) ⇒ ReportCommand
7
8
9
10
11
12
|
# File 'lib/topicz/commands/report_command.rb', line 7
def initialize(config_file = nil, arguments = [])
super(config_file)
@week = Date.today.cweek
@year = Date.today.cwyear
option_parser.order! arguments
end
|
Instance Method Details
#execute ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/topicz/commands/report_command.rb', line 28
def execute
year = @year.to_s
week = @week.to_s.rjust(2, '0')
path = File.join(Topicz::DIR_JOURNAL, "#{year}-week-#{week}.md")
@repository.topics.each do |topic|
journal = File.join(topic.fullpath, path)
next unless File.exist? journal
puts "## #{topic.title}"
puts
puts File.readlines(journal)
.drop(2).join()
.gsub(/^#(.*)/, '##\1')
.strip
puts
end
end
|
#option_parser ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/topicz/commands/report_command.rb', line 14
def option_parser
OptionParser.new do |options|
options.banner = 'Usage: report'
options.on('-w', '--week WEEK', 'Use week WEEK instead of the current week') do |week|
@week = week.to_i
end
options.on('-y', '--year YEAR', 'Use year YEAR instead of the current year') do |year|
@year = year.to_i
end
options.separator ''
options.separator 'Generates a weekly report from all journals across all topics in a single Markdown file.'
end
end
|