Class: ProgressLogger::State
- Inherits:
-
Object
- Object
- ProgressLogger::State
- Defined in:
- lib/progress-logger.rb
Overview
Internal state passed to the ProgressLogger block whenever the criteria are met. count is the current count of triggers processed now is the Time.now value when this action was triggered (useful if you are handling state slowly)
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#now ⇒ Object
readonly
Returns the value of attribute now.
Instance Method Summary collapse
-
#count_delta ⇒ Object
the number of triggers processed since the last action.
-
#long_eta ⇒ Object
the estimated time to complete, based on the long-term speed (long_rate) * raises ArgumentError if you don’t have a :max parameter in the main ProgressLogger constructor * will return nil if this is called on the very first call to trigger, as no time will have elapsed!.
-
#long_rate ⇒ Object
the processing rate, in triggers-per-second, using the count since the first action for a long-term speed * will return nil if this is called on the very first call to trigger, as no time will have elapsed!.
-
#short_eta ⇒ Object
the estimated time to complete, based on the short-term speed (short_rate) * raises ArgumentError if you don’t have a :max parameter in the main ProgressLogger constructor * will return nil if this is called on the very first call to trigger, as no time will have elapsed!.
-
#short_rate ⇒ Object
the processing rate, in triggers-per-second, using the count since the last action for a short-term speed * will return nil if this is called on the very first call to trigger, as no time will have elapsed!.
-
#time_delta ⇒ Object
the amount of time passed since the last action.
-
#time_total ⇒ Object
the amount of time passed since the first trigger (or since ProgressLogger.start was called).
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
73 74 75 |
# File 'lib/progress-logger.rb', line 73 def count @count end |
#now ⇒ Object (readonly)
Returns the value of attribute now.
73 74 75 |
# File 'lib/progress-logger.rb', line 73 def now @now end |
Instance Method Details
#count_delta ⇒ Object
the number of triggers processed since the last action
75 76 77 |
# File 'lib/progress-logger.rb', line 75 def count_delta @count - @last_count end |
#long_eta ⇒ Object
the estimated time to complete, based on the long-term speed (long_rate)
-
raises ArgumentError if you don’t have a :max parameter in the main ProgressLogger constructor
-
will return nil if this is called on the very first call to trigger, as no time will have elapsed!
110 111 112 113 114 115 |
# File 'lib/progress-logger.rb', line 110 def long_eta raise ArgumentError.new("Can't calculate ETA when no max specified") if @max.nil? rate = long_rate return nil if rate.nil? return (@max - @count) / rate end |
#long_rate ⇒ Object
the processing rate, in triggers-per-second, using the count since the first action for a long-term speed
-
will return nil if this is called on the very first call to trigger, as no time will have elapsed!
94 95 96 97 |
# File 'lib/progress-logger.rb', line 94 def long_rate return nil if @now == @start_time (@count - @start_count) / (1.0 * (@now - @start_time)) end |
#short_eta ⇒ Object
the estimated time to complete, based on the short-term speed (short_rate)
-
raises ArgumentError if you don’t have a :max parameter in the main ProgressLogger constructor
-
will return nil if this is called on the very first call to trigger, as no time will have elapsed!
101 102 103 104 105 106 |
# File 'lib/progress-logger.rb', line 101 def short_eta raise ArgumentError.new("Can't calculate ETA when no max specified") if @max.nil? rate = short_rate return nil if rate.nil? return (@max - @count) / rate end |
#short_rate ⇒ Object
the processing rate, in triggers-per-second, using the count since the last action for a short-term speed
-
will return nil if this is called on the very first call to trigger, as no time will have elapsed!
88 89 90 91 |
# File 'lib/progress-logger.rb', line 88 def short_rate return nil if @now == @last_report (@count - @last_count) / (1.0 * (@now - @last_report)) end |
#time_delta ⇒ Object
the amount of time passed since the last action
83 84 85 |
# File 'lib/progress-logger.rb', line 83 def time_delta @now - @last_report end |
#time_total ⇒ Object
the amount of time passed since the first trigger (or since ProgressLogger.start was called)
79 80 81 |
# File 'lib/progress-logger.rb', line 79 def time_total @now - @start_time end |