Class: Envirobly::Duration
- Inherits:
-
Object
- Object
- Envirobly::Duration
- Extended by:
- Colorize
- Defined in:
- lib/envirobly/duration.rb
Constant Summary
Constants included from Colorize
Colorize::BLUE, Colorize::BOLD, Colorize::FAINT, Colorize::GREEN, Colorize::RED, Colorize::RESET, Colorize::YELLOW
Class Method Summary collapse
Methods included from Colorize
bold, cross, display_config_errors, downwards_arrow_to_right, faint, green, green_check, red, yellow
Class Method Details
.format_duration(tms) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/envirobly/duration.rb', line 23 def format_duration(tms) ms = (tms.real * 1000).to_i if ms >= 60_000 minutes = ms / 60_000 seconds = (ms % 60_000) / 1000 sprintf("%dm%ds", minutes, seconds) elsif ms >= 1000 seconds = ms / 1000 sprintf("%ds", seconds) else sprintf("%dms", ms) end end |
.measure(message = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/envirobly/duration.rb', line 9 def measure( = nil) measurement = Benchmark.measure do yield end duration = format_duration(measurement) if .nil? puts [ "", green_check, faint(duration) ].join(" ") else puts sprintf(, duration) end end |