Class: Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_commands.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimer

Returns a new instance of Timer.



1035
1036
1037
# File 'lib/dev_commands.rb', line 1035

def initialize
  @start_time=Time.now
end

Instance Attribute Details

#start_timeObject

Returns the value of attribute start_time.



1033
1034
1035
# File 'lib/dev_commands.rb', line 1033

def start_time
  @start_time
end

Class Method Details

.elapsed_exceeds?(name, duration_seconds) ⇒ Boolean

Returns:

  • (Boolean)


1047
1048
1049
1050
1051
1052
# File 'lib/dev_commands.rb', line 1047

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) ⇒ Object



1054
1055
1056
1057
1058
# File 'lib/dev_commands.rb', line 1054

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

.get_timestamp(name) ⇒ Object



1060
1061
1062
1063
1064
1065
1066
# File 'lib/dev_commands.rb', line 1060

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

.set_timestamp(name) ⇒ Object



1068
1069
1070
1071
# File 'lib/dev_commands.rb', line 1068

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

Instance Method Details

#elapsedObject

in seconds



1039
1040
1041
# File 'lib/dev_commands.rb', line 1039

def elapsed # in seconds

  return Time.now-@start_time
end

#elapsed_strObject



1043
1044
1045
# File 'lib/dev_commands.rb', line 1043

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