Sha256: 57c1e6c13d8050bac37717022f6720ccd291662bbbaf69dc6876df4f7df8ec59

Contents?: true

Size: 985 Bytes

Versions: 37

Compression:

Stored size: 985 Bytes

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?("#{DEV[:dev_root]}/log/#{name}.timestamp"))
      return Time.parse(File.read("#{DEV[:dev_root]}/log/#{name}.timestamp").strip)
	end
	nil
  end

  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
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
dev_commands-0.0.56 lib/timer.rb
dev_commands-0.0.55 lib/timer.rb
dev_commands-0.0.49 lib/timer.rb
dev_commands-0.0.48 lib/timer.rb
dev_commands-0.0.47 lib/timer.rb
dev_commands-0.0.46 lib/timer.rb
dev_commands-0.0.45 lib/timer.rb
dev_commands-0.0.44 lib/timer.rb
dev_commands-0.0.43 lib/timer.rb
dev_commands-0.0.42 lib/timer.rb
dev_commands-0.0.41 lib/timer.rb
dev_commands-0.0.40 lib/timer.rb
dev_commands-0.0.39 lib/timer.rb
dev_commands-0.0.38 lib/timer.rb
dev_commands-0.0.37 lib/timer.rb
dev_commands-0.0.36 lib/timer.rb
dev_commands-0.0.35 lib/timer.rb
dev_commands-0.0.34 lib/timer.rb
dev_commands-0.0.25 lib/timer.rb
dev_commands-0.0.24 lib/timer.rb