Class: ProgressBar::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby-progressbar/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby-progressbar/base.rb', line 16

def initialize(options = {})
  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

Instance Method Details

#decrementObject



88
89
90
# File 'lib/ruby-progressbar/base.rb', line 88

def decrement
  update_progress(:decrement)
end

#finishObject



46
47
48
49
50
51
52
# File 'lib/ruby-progressbar/base.rb', line 46

def finish
  output.with_refresh do
    self.finished = true
    progressable.finish
    timer.stop
  end unless finished?
end

#finished?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/ruby-progressbar/base.rb', line 80

def finished?
  finished || (autofinish && progressable.finished?)
end

#format=(other) ⇒ Object Also known as: format



130
131
132
133
134
# File 'lib/ruby-progressbar/base.rb', line 130

def format=(other)
  output.refresh_with_format_change do
    @format = Format::String.new(other || output.default_format)
  end
end

#incrementObject



92
93
94
# File 'lib/ruby-progressbar/base.rb', line 92

def increment
  update_progress(:increment)
end

#inspectObject



126
127
128
# File 'lib/ruby-progressbar/base.rb', line 126

def inspect
  "#<ProgressBar:#{progress}/#{total || 'unknown'}>"
end

#pauseObject



54
55
56
# File 'lib/ruby-progressbar/base.rb', line 54

def pause
  output.with_refresh { timer.pause } unless paused?
end

#progress=(new_progress) ⇒ Object



96
97
98
# File 'lib/ruby-progressbar/base.rb', line 96

def progress=(new_progress)
  update_progress(:progress=, new_progress)
end

#progress_mark=(mark) ⇒ Object



104
105
106
# 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) ⇒ Object



108
109
110
# File 'lib/ruby-progressbar/base.rb', line 108

def remainder_mark=(mark)
  output.refresh_with_format_change { bar.remainder_mark = mark }
end

#resetObject



66
67
68
69
70
71
72
# File 'lib/ruby-progressbar/base.rb', line 66

def reset
  output.with_refresh do
    self.finished = false
    progressable.reset
    timer.reset
  end
end

#resumeObject



62
63
64
# File 'lib/ruby-progressbar/base.rb', line 62

def resume
  output.with_refresh { timer.resume } if stopped?
end

#start(options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/ruby-progressbar/base.rb', line 39

def start(options = {})
  clear

  timer.start
  update_progress(:start, options)
end

#started?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/ruby-progressbar/base.rb', line 84

def started?
  timer.started?
end

#stopObject



58
59
60
# File 'lib/ruby-progressbar/base.rb', line 58

def stop
  output.with_refresh { timer.stop } unless stopped?
end

#stopped?Boolean Also known as: paused?

Returns:

  • (Boolean)


74
75
76
# File 'lib/ruby-progressbar/base.rb', line 74

def stopped?
  timer.stopped? || finished?
end

#titleObject



112
113
114
# File 'lib/ruby-progressbar/base.rb', line 112

def title
  title_comp.title
end

#title=(title) ⇒ Object



116
117
118
# File 'lib/ruby-progressbar/base.rb', line 116

def title=(title)
  output.refresh_with_format_change { title_comp.title = title }
end

#to_s(new_format = nil) ⇒ Object



120
121
122
123
124
# 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) ⇒ Object



100
101
102
# File 'lib/ruby-progressbar/base.rb', line 100

def total=(new_total)
  update_progress(:total=, new_total)
end