Class: BundlerTimer::Statistics

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bundler_timer/statistics.rb

Instance Method Summary collapse

Constructor Details

#initializeStatistics

Returns a new instance of Statistics.



11
12
13
14
15
# File 'lib/bundler_timer/statistics.rb', line 11

def initialize
  create_storage_dir
  create_database
  super
end

Instance Method Details

#record(task, &block) ⇒ Object



17
18
19
20
21
22
# File 'lib/bundler_timer/statistics.rb', line 17

def record(task, &block)
  time = Benchmark.realtime do
    yield
  end
  @db[:executions].insert :command => task, :runtime => time, :run_at => Date.today
end

#totalObject



24
25
26
# File 'lib/bundler_timer/statistics.rb', line 24

def total
  @db[:executions].sum(:runtime)
end

#total_for_day(day = Date.today) ⇒ Object



28
29
30
# File 'lib/bundler_timer/statistics.rb', line 28

def total_for_day(day = Date.today)
  @db[:executions].where(:run_at => day).sum(:runtime)
end

#ugly_outputObject



32
33
34
# File 'lib/bundler_timer/statistics.rb', line 32

def ugly_output
  puts "\n\tCongratulations, you've spent #{smart_time(total_for_day)} today staring at your screen (#{smart_time(total)} overall)."
end