Sha256: 1c656d0f51d1edd8332ad57506cd9df6c296884cadbbea3efff675ef806ae813

Contents?: true

Size: 1.01 KB

Versions: 75

Compression:

Stored size: 1.01 KB

Contents

class Timer
  attr_accessor :start_time

  def initialize
    @start_time=Time.now
  end

  def elapsed # in seconds
    return Time.now-@start_time
  end

  def elapsed_str
    elapsed_str="[" + "%.0f" %(elapsed) + "s]"
  end

  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

  def self.get_elapsed(name)
    timestamp=get_timestamp(name)
	return Time.now-timestamp if(!timestamp.nil?)
	nil
  end

  def self.get_timestamp(name)
    dir=Rake.application.original_dir
    if(File.exists?("#{dir}/log/#{name}.timestamp"))
      return Time.parse(File.read("#{dir}/log/#{name}.timestamp").strip)
	end
	nil
  end

  def self.set_timestamp(name)
    Dir.mkdir("#{DEV_TASKS[:working_directory]}/log") if(!Dir.exists?("#{DEV_TASKS[:working_directory]}/log"))
    File.open("#{DEV_TASKS[:working_directory]}/log/#{name}.timestamp",'w'){|f|f.puts(Time.now.to_s)}
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
dev_tasks-1.0.8 lib/timer.rb
dev_tasks-1.0.7 lib/timer.rb
dev_tasks-1.0.6 lib/timer.rb
dev_tasks-1.0.5 lib/timer.rb
dev_tasks-1.0.4 lib/timer.rb
dev_tasks-1.0.3 lib/timer.rb
dev_tasks-1.0.2 lib/timer.rb
dev_tasks-1.0.1 lib/timer.rb
dev_tasks-0.0.167 lib/timer.rb
dev_tasks-1.0.0 lib/timer.rb
dev_tasks-0.0.166 lib/timer.rb
dev_tasks-0.0.164 lib/timer.rb
dev_tasks-0.0.163 lib/timer.rb
dev_tasks-0.0.162 lib/timer.rb
dev_tasks-0.0.161 lib/timer.rb
dev_tasks-0.0.160 lib/timer.rb
dev_tasks-0.0.159 lib/timer.rb
dev_tasks-0.0.158 lib/timer.rb
dev_tasks-0.0.157 lib/timer.rb
dev_tasks-0.0.156 lib/timer.rb