Class: ProgressBar::Base
- Inherits:
-
Object
- Object
- ProgressBar::Base
- Extended by:
- Forwardable
- Defined in:
- lib/ruby-progressbar/base.rb
Instance Method Summary collapse
- #decrement ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
- #format=(other) ⇒ Object (also: #format)
- #increment ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #pause ⇒ Object
- #progress=(new_progress) ⇒ Object
- #progress_mark=(mark) ⇒ Object
- #remainder_mark=(mark) ⇒ Object
- #reset ⇒ Object
- #resume ⇒ Object
- #start(options = {}) ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #stopped? ⇒ Boolean (also: #paused?)
- #title ⇒ Object
- #title=(title) ⇒ Object
- #to_s(new_format = nil) ⇒ Object
- #total=(new_total) ⇒ Object
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( = {}) self.autostart = .fetch(:autostart, true) self.autofinish = .fetch(:autofinish, true) self.finished = false self.timer = Timer.new() self.progressable = Progress.new() = .merge(:timer => timer, :progress => progressable) self.title_comp = Components::Title.new() self. = Components::Bar.new() self.percentage = Components::Percentage.new() self.rate = Components::Rate.new() self.time = Components::Time.new() self.output = Output.detect(.merge(:bar => self)) @format = Format::String.new(output.resolve_format([:format])) start :at => [:starting_at] if autostart end |
Instance Method Details
#decrement ⇒ Object
88 89 90 |
# File 'lib/ruby-progressbar/base.rb', line 88 def decrement update_progress(:decrement) end |
#finish ⇒ Object
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
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 |
#increment ⇒ Object
92 93 94 |
# File 'lib/ruby-progressbar/base.rb', line 92 def increment update_progress(:increment) end |
#inspect ⇒ Object
126 127 128 |
# File 'lib/ruby-progressbar/base.rb', line 126 def inspect "#<ProgressBar:#{progress}/#{total || 'unknown'}>" end |
#pause ⇒ Object
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 { .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 { .remainder_mark = mark } end |
#reset ⇒ Object
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 |
#resume ⇒ Object
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( = {}) clear timer.start update_progress(:start, ) end |
#started? ⇒ Boolean
84 85 86 |
# File 'lib/ruby-progressbar/base.rb', line 84 def started? timer.started? end |
#stop ⇒ Object
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?
74 75 76 |
# File 'lib/ruby-progressbar/base.rb', line 74 def stopped? timer.stopped? || finished? end |
#title ⇒ Object
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 |