Sha256: 9516689f3f9f7f6e1f66b94ca91ae3ea3bfa0eb6f154a83bd45161c3c11f875e

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

module ApplicationView
  module Support
    module Timer
      def time(message="")
        start_time = Time.now
        yield
        end_time = Time.now
        put_elapsed_time(start_time, end_time, message)
      end
    
      def put_elapsed_time(start_time, end_time, message="")
        seconds = end_time - start_time
        if seconds > 59
          minutes = seconds / 60.0
          seconds = (minutes - minutes.to_i) * 60
    
          m = minutes.to_i > 1 ? "minutes" : "minute"
          elapsed_time = "#{minutes.to_i} #{m}"
          if seconds > 0
            s = seconds.to_i > 1 ? "seconds" : "minutes"
            elapsed_time += ", #{seconds.to_i} #{s}"
          end
        else
          s = seconds.to_i > 1 ? "seconds" : "minutes"
          elapsed_time = "#{seconds.to_i} #{s}"
        end
  
        puts
        e = ""
        unless message.blank?
          message += ". "
        end
        e = message + e
        e += "Elapsed time: #{elapsed_time}"
        puts e
        g(e)
      end    
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ymdp-0.0.10 lib/application_view/support/timer.rb
ymdp-0.0.9 lib/application_view/support/timer.rb
ymdp-0.0.8 lib/application_view/support/timer.rb
ymdp-0.0.7 lib/application_view/support/timer.rb
ymdp-0.0.6 lib/application_view/support/timer.rb
ymdp-0.0.5 lib/application_view/support/timer.rb
ymdp-0.0.4 lib/application_view/support/timer.rb
ymdp-0.0.3 lib/application_view/support/timer.rb