Class: ProgressLogger::State

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



73
74
75
# File 'lib/progress-logger.rb', line 73

def count
  @count
end

#nowObject (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_deltaObject

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_etaObject

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!

Raises:

  • (ArgumentError)


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_rateObject

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_etaObject

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!

Raises:

  • (ArgumentError)


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_rateObject

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_deltaObject

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_totalObject

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