Class: Topicz::Commands::JournalCommand
- Inherits:
-
EditorCommand
- Object
- RepositoryCommand
- EditorCommand
- Topicz::Commands::JournalCommand
- Defined in:
- lib/topicz/commands/journal_command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(config_file = nil, arguments = [], kernel = Kernel) ⇒ JournalCommand
constructor
A new instance of JournalCommand.
- #option_parser ⇒ Object
Methods inherited from EditorCommand
Methods inherited from RepositoryCommand
#find_exactly_one_topic, #load_config, #load_repository, #process_excludes
Constructor Details
#initialize(config_file = nil, arguments = [], kernel = Kernel) ⇒ JournalCommand
Returns a new instance of JournalCommand.
10 11 12 13 14 15 16 17 18 |
# File 'lib/topicz/commands/journal_command.rb', line 10 def initialize(config_file = nil, arguments = [], kernel = Kernel) super(config_file) @kernel = kernel @strict = false @week = Date.today.cweek @year = Date.today.cwyear option_parser.order! arguments @filter = arguments.join ' ' end |
Instance Method Details
#execute ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/topicz/commands/journal_command.rb', line 45 def execute topic = find_exactly_one_topic(@filter, @strict) path = File.join(topic.fullpath, Topicz::DIR_JOURNAL) FileUtils.mkdir(path) unless Dir.exist? path year = @year.to_s week = @week.to_s.rjust(2, '0') path = File.join(path, "#{year}-week-#{week}.md") unless File.exists? path File.open(path, 'w') do |file| file.puts("# #{topic.title} - Week #{week}, #{year}") end end @kernel.exec "#{editor} \"#{path}\"" end |
#option_parser ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/topicz/commands/journal_command.rb', line 20 def option_parser OptionParser.new do || . = 'Usage: journal <filter>' .on('-s', '--strict', 'Do a full strict match on topic IDs only') do @strict = true end .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 'Opens the weekly journal for the specified topic.' .separator '' .separator 'The filter specifies the text to search on. The text is matched against the topic\'s: ' .separator '- path on the filesystem' .separator '- id, if specified in the topic\'s topic.yaml file' .separator '- title, if specified in the topic\'s topic.yaml file' .separator '- aliases, if specified in the topic\'s topic.yaml file' .separator '' .separator 'The filter must return precisely one topic. Zero or more matches give an error.' end end |