Class: Logbook::CLI::App

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

Class Method Summary collapse

Class Method Details

.stats(paths) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/logbook/cli/app.rb', line 3

def self.stats(paths)
  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)
      duration = page.total_duration.minutes.to_i

      hours = duration / 60
      minutes = duration % 60

      puts "#{name}: #{hours}h#{minutes}min"
    end
  end
end