Class: Timer
- Inherits:
-
Object
- Object
- Timer
- Defined in:
- lib/dev_commands.rb
Instance Attribute Summary collapse
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Class Method Summary collapse
- .elapsed_exceeds?(name, duration_seconds) ⇒ Boolean
- .get_elapsed(name) ⇒ Object
- .get_timestamp(name) ⇒ Object
- .set_timestamp(name) ⇒ Object
Instance Method Summary collapse
-
#elapsed ⇒ Object
in seconds.
- #elapsed_str ⇒ Object
-
#initialize ⇒ Timer
constructor
A new instance of Timer.
Constructor Details
#initialize ⇒ Timer
Returns a new instance of Timer.
1020 1021 1022 |
# File 'lib/dev_commands.rb', line 1020 def initialize @start_time=Time.now end |
Instance Attribute Details
#start_time ⇒ Object
Returns the value of attribute start_time.
1018 1019 1020 |
# File 'lib/dev_commands.rb', line 1018 def start_time @start_time end |
Class Method Details
.elapsed_exceeds?(name, duration_seconds) ⇒ Boolean
1032 1033 1034 1035 1036 1037 |
# File 'lib/dev_commands.rb', line 1032 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
1039 1040 1041 1042 1043 |
# File 'lib/dev_commands.rb', line 1039 def self.get_elapsed(name) =(name) return Time.now- if(!.nil?) nil end |
.get_timestamp(name) ⇒ Object
1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/dev_commands.rb', line 1045 def self.(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
1053 1054 1055 1056 |
# File 'lib/dev_commands.rb', line 1053 def self.(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
#elapsed ⇒ Object
in seconds
1024 1025 1026 |
# File 'lib/dev_commands.rb', line 1024 def elapsed # in seconds return Time.now-@start_time end |
#elapsed_str ⇒ Object
1028 1029 1030 |
# File 'lib/dev_commands.rb', line 1028 def elapsed_str elapsed_str="[" + "%.0f" %(elapsed) + "s]" end |