Class: Topicz::Commands::ReportCommand
- Inherits:
-
RepositoryCommand
- Object
- RepositoryCommand
- Topicz::Commands::ReportCommand
- Defined in:
- lib/topicz/commands/report_command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(config_file = nil, arguments = []) ⇒ ReportCommand
constructor
A new instance of ReportCommand.
- #option_parser ⇒ Object
Methods inherited from RepositoryCommand
#find_exactly_one_topic, #load_config, #load_repository, #process_excludes
Constructor Details
#initialize(config_file = nil, arguments = []) ⇒ ReportCommand
Returns a new instance of ReportCommand.
8 9 10 11 12 13 14 |
# File 'lib/topicz/commands/report_command.rb', line 8 def initialize(config_file = nil, arguments = []) super(config_file) @week = Date.today.cweek @year = Date.today.cwyear option_parser.order! arguments @filter = arguments.join ' ' end |
Instance Method Details
#execute ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/topicz/commands/report_command.rb', line 30 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() # Drop first 2 lines: title (week) and empty line .gsub(/^#(.*)/, '##\1') # Add an extra '#' in front of every title .strip # Remove leading and ending whitespace puts end end |
#option_parser ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/topicz/commands/report_command.rb', line 16 def option_parser OptionParser.new do || . = 'Usage: report' .on('-w', '--week WEEK', 'Use week WEEK instead of the current week') do |week| @week = week.to_i end .on('-y', '--year YEAR', 'Use year YEAR instead of the current year') do |year| @year = year.to_i end .separator '' .separator 'Generates a weekly report from all journals across all topics.' end end |