class Timer

Attributes

start_time[RW]

Public Class Methods

elapsed_exceeds?(name,duration_seconds) click to toggle source
# File lib/timer.rb, line 16
def self.elapsed_exceeds?(name,duration_seconds)
  if(Timer.get_elapsed(name).nil? || Timer.get_elapsed(name) > duration_seconds)
        return true
      end
      return false
end
get_elapsed(name) click to toggle source
# File lib/timer.rb, line 23
def self.get_elapsed(name)
  timestamp=get_timestamp(name)
      return Time.now-timestamp if(!timestamp.nil?)
      nil
end
get_timestamp(name) click to toggle source
# File lib/timer.rb, line 29
def self.get_timestamp(name)
  dir=Rake.application.original_dir
  if(File.exists?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
    return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
      end
      nil
end
new() click to toggle source
# File lib/timer.rb, line 4
def initialize
  @start_time=Time.now
end
set_timestamp(name) click to toggle source
# File lib/timer.rb, line 37
def self.set_timestamp(name)
  Dir.mkdir("#{DEV_TASKS[:dev_root]}/log") if(!Dir.exists?("#{DEV_TASKS[:dev_root]}/log"))
  File.open("#{DEV_TASKS[:dev_root]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
end

Public Instance Methods

elapsed() click to toggle source
# File lib/timer.rb, line 8
def elapsed # in seconds
  return Time.now-@start_time
end
elapsed_str() click to toggle source
# File lib/timer.rb, line 12
def elapsed_str
  elapsed_str="[" + "%.0f" %(elapsed) + "s]"
end