Class: BundlerTimer::Statistics
- Inherits:
-
Object
- Object
- BundlerTimer::Statistics
- Includes:
- Singleton
- Defined in:
- lib/bundler_timer/statistics.rb
Instance Method Summary collapse
-
#initialize ⇒ Statistics
constructor
A new instance of Statistics.
- #record(task, &block) ⇒ Object
- #total ⇒ Object
- #total_for_day(day = Date.today) ⇒ Object
- #ugly_output ⇒ Object
Constructor Details
#initialize ⇒ Statistics
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 |
#total ⇒ Object
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_output ⇒ Object
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 |