Class: ProgressBar::Components::Rate

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-progressbar/components/rate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rate

Returns a new instance of Rate.



8
9
10
11
12
# File 'lib/ruby-progressbar/components/rate.rb', line 8

def initialize(options = {})
  self.rate_scale = options[:rate_scale] || lambda { |x| x }
  self.timer      = options[:timer]
  self.progress   = options[:progress]
end

Instance Attribute Details

#progressObject

Returns the value of attribute progress.



4
5
6
# File 'lib/ruby-progressbar/components/rate.rb', line 4

def progress
  @progress
end

#rate_scaleObject

Returns the value of attribute rate_scale.



4
5
6
# File 'lib/ruby-progressbar/components/rate.rb', line 4

def rate_scale
  @rate_scale
end

#timerObject

Returns the value of attribute timer.



4
5
6
# File 'lib/ruby-progressbar/components/rate.rb', line 4

def timer
  @timer
end

Instance Method Details

#rate_of_change(format_string = '%i') ⇒ Object



14
15
16
17
18
# File 'lib/ruby-progressbar/components/rate.rb', line 14

def rate_of_change(format_string = '%i')
  return '0' if elapsed_seconds <= 0

  format_string % scaled_rate
end

#rate_of_change_with_precisionObject



20
21
22
# File 'lib/ruby-progressbar/components/rate.rb', line 20

def rate_of_change_with_precision
  rate_of_change('%.2f')
end