class ProgressBar::Base

Attributes

autofinish[RW]
autostart[RW]
bar[RW]
finished[RW]
output[RW]
percentage[RW]
progressable[RW]
rate[RW]
time[RW]
timer[RW]
title_comp[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/ruby-progressbar/base.rb, line 16
def initialize(options = {}) # rubocop:disable Metrics/AbcSize
  self.autostart    = options.fetch(:autostart,  true)
  self.autofinish   = options.fetch(:autofinish, true)
  self.finished     = false

  self.timer        = Timer.new(options)
  self.progressable = Progress.new(options)

  options           = options.merge(:timer    => timer,
                                    :progress => progressable)

  self.title_comp   = Components::Title.new(options)
  self.bar          = Components::Bar.new(options)
  self.percentage   = Components::Percentage.new(options)
  self.rate         = Components::Rate.new(options)
  self.time         = Components::Time.new(options)

  self.output       = Output.detect(options.merge(:bar => self))
  @format           = Format::String.new(output.resolve_format(options[:format]))

  start :at => options[:starting_at] if autostart
end

Public Instance Methods

decrement() click to toggle source
# File lib/ruby-progressbar/base.rb, line 88
def decrement
  update_progress(:decrement)
end
finish() click to toggle source
# File lib/ruby-progressbar/base.rb, line 44
def finish
  return if finished?

  output.with_refresh do
    self.finished = true
    progressable.finish
    timer.stop
  end
end
finished?() click to toggle source
# File lib/ruby-progressbar/base.rb, line 80
def finished?
  finished || (autofinish && progressable.finished?)
end
format(other)
Alias for: format=
format=(other) click to toggle source
# File lib/ruby-progressbar/base.rb, line 154
def format=(other)
  output.refresh_with_format_change do
    @format = Format::String.new(other || output.default_format)
  end
end
Also aliased as: format
increment() click to toggle source
# File lib/ruby-progressbar/base.rb, line 92
def increment
  update_progress(:increment)
end
inspect() click to toggle source

rubocop:enable Metrics/AbcSize, Layout/LineLength

# File lib/ruby-progressbar/base.rb, line 150
def inspect
  "#<ProgressBar:#{progress}/#{total || 'unknown'}>"
end
pause() click to toggle source
# File lib/ruby-progressbar/base.rb, line 54
def pause
  output.with_refresh { timer.pause } unless paused?
end
paused?()
Alias for: stopped?
progress=(new_progress) click to toggle source
# File lib/ruby-progressbar/base.rb, line 96
def progress=(new_progress)
  update_progress(:progress=, new_progress)
end
progress_mark=(mark) click to toggle source
# File lib/ruby-progressbar/base.rb, line 104
def progress_mark=(mark)
  output.refresh_with_format_change { bar.progress_mark = mark }
end
remainder_mark=(mark) click to toggle source
# File lib/ruby-progressbar/base.rb, line 108
def remainder_mark=(mark)
  output.refresh_with_format_change { bar.remainder_mark = mark }
end
reset() click to toggle source
# File lib/ruby-progressbar/base.rb, line 66
def reset
  output.with_refresh do
    self.finished = false
    progressable.reset
    timer.reset
  end
end
resume() click to toggle source
# File lib/ruby-progressbar/base.rb, line 62
def resume
  output.with_refresh { timer.resume } if stopped?
end
start(options = {}) click to toggle source
# File lib/ruby-progressbar/base.rb, line 39
def start(options = {})
  timer.start
  update_progress(:start, options)
end
started?() click to toggle source
# File lib/ruby-progressbar/base.rb, line 84
def started?
  timer.started?
end
stop() click to toggle source
# File lib/ruby-progressbar/base.rb, line 58
def stop
  output.with_refresh { timer.stop } unless stopped?
end
stopped?() click to toggle source
# File lib/ruby-progressbar/base.rb, line 74
def stopped?
  timer.stopped? || finished?
end
Also aliased as: paused?
title() click to toggle source
# File lib/ruby-progressbar/base.rb, line 112
def title
  title_comp.title
end
title=(title) click to toggle source
# File lib/ruby-progressbar/base.rb, line 116
def title=(title)
  output.refresh_with_format_change { title_comp.title = title }
end
to_h() click to toggle source

rubocop:disable Metrics/AbcSize, Layout/LineLength

# File lib/ruby-progressbar/base.rb, line 127
def to_h
  {
    'output_stream'                       => output.__send__(:stream),
    'length'                              => output.length,
    'title'                               => title_comp.title,
    'progress_mark'                       => bar.progress_mark,
    'remainder_mark'                      => bar.remainder_mark,
    'progress'                            => progressable.progress,
    'total'                               => progressable.total,
    'percentage'                          => progressable.percentage_completed_with_precision.to_f,
    'elapsed_time_in_seconds'             => time.__send__(:timer).elapsed_seconds,
    'estimated_time_remaining_in_seconds' => time.__send__(:estimated_seconds_remaining),
    'base_rate_of_change'                 => rate.__send__(:base_rate),
    'scaled_rate_of_change'               => rate.__send__(:scaled_rate),
    'unknown_progress_animation_steps'    => bar.upa_steps,
    'throttle_rate'                       => output.__send__(:throttle).rate,
    'started?'                            => started?,
    'stopped?'                            => stopped?,
    'finished?'                           => finished?
  }
end
to_s(new_format = nil) click to toggle source
# File lib/ruby-progressbar/base.rb, line 120
def to_s(new_format = nil)
  self.format = new_format if new_format

  Format::Formatter.process(@format, output.length, self)
end
total=(new_total) click to toggle source
# File lib/ruby-progressbar/base.rb, line 100
def total=(new_total)
  update_progress(:total=, new_total)
end

Protected Instance Methods

update_progress(*args) click to toggle source
# File lib/ruby-progressbar/base.rb, line 176
def update_progress(*args)
  output.with_refresh do
    progressable.__send__(*args)
    timer.stop if finished?
  end
end