Class: Logbook::CLI::App

Inherits:
Object
  • Object
show all
Defined in:
lib/logbook/cli/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



3
4
# File 'lib/logbook/cli/app.rb', line 3

def initialize
end

Class Method Details

.stats(paths, options = {}) ⇒ Object



6
7
8
# File 'lib/logbook/cli/app.rb', line 6

def self.stats(paths, options = {})
  new.stats(paths, options)
end

Instance Method Details

#stats(paths, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/logbook/cli/app.rb', line 10

def stats(paths, options)
  return if paths.empty?

  paths.select { |path| File.file?(path) }.each do |path|
    name = File.basename(path)
    contents = File.read(path)

    if page = Logbook::Builder.build(contents)
      total_duration = page.logged_time.minutes.to_i
      next unless total_duration > 0

      puts "#{name}: #{format_duration(total_duration)}"

      if options[:per_task]
        page.tasks.each do |_, task|
          task_duration = task.time_logged.minutes.to_i
          next unless task_duration > 0

          puts " " * (name.length + 1) + " #{task.title}: #{format_duration(task_duration)}"
        end
      end
    end
  end
end