Module: TimeTaken
- Defined in:
- lib/time_taken/version.rb,
lib/time_taken/time_taken.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.time_taken(format = :milli_seconds, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/time_taken/time_taken.rb', line 5 def self.time_taken(format=:milli_seconds, &block) if block_given? && valid_format?(format) start_time = Time.now block.call end_time = Time.now ((end_time - start_time) * @time_formats[format]) else 0 end end |
.valid_format?(format) ⇒ Boolean
16 17 18 |
# File 'lib/time_taken/time_taken.rb', line 16 def self.valid_format? format !@time_formats[format].nil? end |