Class: Pomodoro::Commands::Review

Inherits:
Command
  • Object
show all
Defined in:
lib/pomodoro/commands/review.rb

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Pomodoro::Commands::Command

Instance Method Details

#runObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pomodoro/commands/review.rb', line 12

def run
  period, date = self.get_period_and_date(:day)
  router = Pomodoro::Router.new(self.config.data_root_path, date)

  abort t(:cannot_be_past_today) if date > Date.today

  router = Pomodoro::Router.new(self.config.data_root_path, date)

  # TODO: refactor this.
  if period.nil? || period == :day
    # TODO: more templates.
    path = self.config.today_path(date).sub(/\.today$/, '_review.md')
    unless File.exist?(path)
      # TODO: add balances if it's Saturday.
      # TODO: Template(s) should be user-defined.
      File.open(path, 'w') do |file|
        file.puts <<-EOF.gsub(/^ +/, '')
          # Expenses
          # Activities
          # Consumption
          # Medications
          # Medical data
        EOF
      end
    end

    command("nvim #{path}")
  elsif router.respond_to?(:"#{period}_review_path")
    path = router.send(:"#{period}_review_path")
    command("nvim #{path}")
  else
    raise t(:unknown_period, period: period)
  end
end