Class: Pomodoro::Commands::Report

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

Overview

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#runObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pomodoro/commands/report.rb', line 9

def run
  today_list = parse_today_list(self.config).task_list if File.exist?(self.config.today_path)
  pattern = @args.shift
  selected_time_frames = today_list.time_frames.select { |time_frame| time_frame.name.match(/#{pattern}/) }
  selected_time_frames.each do |time_frame|
    puts "<cyan>#{time_frame.name}</cyan>"
    time_frame.tasks.each do |task|
      # Copied from bitbar.
      hash = {in_progress: 'yellow', completed: 'green', postponed: 'yellow'}
      hash.default_proc = Proc.new { 'bright_black' }
      colour = hash[task.status_x]

      print "<#{colour}>#{task}</#{colour}>"
    end
  end

  puts "\n<bold>Total time:</bold> #{selected_time_frames.reduce(0) { |sum, time_frame| time_frame.actual_duration + sum }}"
  puts "<bold>Cistyho casu:</bold> #{selected_time_frames.reduce(0) { |sum, time_frame| time_frame.duration_ + sum }}"
end