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
rubocop:disable Metrics/AbcSize.
- #inspect ⇒ Object
- #pause ⇒ Object
- #progress=(new_progress) ⇒ Object
- #progress_mark=(mark) ⇒ Object
- #remainder_mark=(mark) ⇒ Object
- #reset ⇒ Object
- #resume ⇒ Object
-
#start(options = {}) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #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
rubocop:disable Metrics/AbcSize
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby-progressbar/base.rb', line 17 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
90 91 92 |
# File 'lib/ruby-progressbar/base.rb', line 90 def decrement update_progress(:decrement) end |
#finish ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ruby-progressbar/base.rb', line 48 def finish output.with_refresh do self.finished = true progressable.finish timer.stop end unless finished? end |
#finished? ⇒ Boolean
82 83 84 |
# File 'lib/ruby-progressbar/base.rb', line 82 def finished? finished || (autofinish && progressable.finished?) end |
#format=(other) ⇒ Object Also known as: format
132 133 134 135 136 |
# File 'lib/ruby-progressbar/base.rb', line 132 def format=(other) output.refresh_with_format_change do @format = Format::String.new(other || output.default_format) end end |
#increment ⇒ Object
94 95 96 |
# File 'lib/ruby-progressbar/base.rb', line 94 def increment update_progress(:increment) end |
#inspect ⇒ Object
128 129 130 |
# File 'lib/ruby-progressbar/base.rb', line 128 def inspect "#<ProgressBar:#{progress}/#{total || 'unknown'}>" end |
#pause ⇒ Object
56 57 58 |
# File 'lib/ruby-progressbar/base.rb', line 56 def pause output.with_refresh { timer.pause } unless paused? end |
#progress=(new_progress) ⇒ Object
98 99 100 |
# File 'lib/ruby-progressbar/base.rb', line 98 def progress=(new_progress) update_progress(:progress=, new_progress) end |
#progress_mark=(mark) ⇒ Object
106 107 108 |
# File 'lib/ruby-progressbar/base.rb', line 106 def progress_mark=(mark) output.refresh_with_format_change { .progress_mark = mark } end |
#remainder_mark=(mark) ⇒ Object
110 111 112 |
# File 'lib/ruby-progressbar/base.rb', line 110 def remainder_mark=(mark) output.refresh_with_format_change { .remainder_mark = mark } end |
#reset ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/ruby-progressbar/base.rb', line 68 def reset output.with_refresh do self.finished = false progressable.reset timer.reset end end |
#resume ⇒ Object
64 65 66 |
# File 'lib/ruby-progressbar/base.rb', line 64 def resume output.with_refresh { timer.resume } if stopped? end |
#start(options = {}) ⇒ Object
rubocop:enable Metrics/AbcSize
41 42 43 44 45 46 |
# File 'lib/ruby-progressbar/base.rb', line 41 def start( = {}) clear timer.start update_progress(:start, ) end |
#started? ⇒ Boolean
86 87 88 |
# File 'lib/ruby-progressbar/base.rb', line 86 def started? timer.started? end |
#stop ⇒ Object
60 61 62 |
# File 'lib/ruby-progressbar/base.rb', line 60 def stop output.with_refresh { timer.stop } unless stopped? end |
#stopped? ⇒ Boolean Also known as: paused?
76 77 78 |
# File 'lib/ruby-progressbar/base.rb', line 76 def stopped? timer.stopped? || finished? end |
#title ⇒ Object
114 115 116 |
# File 'lib/ruby-progressbar/base.rb', line 114 def title title_comp.title end |
#title=(title) ⇒ Object
118 119 120 |
# File 'lib/ruby-progressbar/base.rb', line 118 def title=(title) output.refresh_with_format_change { title_comp.title = title } end |
#to_s(new_format = nil) ⇒ Object
122 123 124 125 126 |
# File 'lib/ruby-progressbar/base.rb', line 122 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
102 103 104 |
# File 'lib/ruby-progressbar/base.rb', line 102 def total=(new_total) update_progress(:total=, new_total) end |