Class: ProgressBar::Base
- Inherits:
-
Object
- Object
- ProgressBar::Base
- Extended by:
- Forwardable
- Defined in:
- lib/ruby-progressbar/base.rb
Constant Summary collapse
- SMOOTHING_DEPRECATION_WARNING =
rubocop:disable Layout/HeredocIndentation
<<-HEREDOC.tr("\n", ' ') WARNING: Passing the 'smoothing' option is deprecated and will be removed in version 2.0. Please pass { projector: { type: 'smoothing', strength: 0.x }}. For more information on why this change is happening, visit https://github.com/jfelchner/ruby-progressbar/wiki/Upgrading HEREDOC
- RUNNING_AVERAGE_RATE_DEPRECATION_WARNING =
<<-HEREDOC.tr("\n", ' ') WARNING: Passing the 'running_average_rate' option is deprecated and will be removed in version 2.0. Please pass { projector: { type: 'smoothing', strength: 0.x }}. For more information on why this change is happening, visit https://github.com/jfelchner/ruby-progressbar/wiki/Upgrading HEREDOC
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
rubocop:enable Metrics/AbcSize, Layout/LineLength.
- #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_h ⇒ Object
rubocop:disable Metrics/AbcSize, Layout/LineLength.
- #to_s(new_format = nil) ⇒ Object
- #total=(new_total) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
rubocop:disable Metrics/AbcSize
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby-progressbar/base.rb', line 45 def initialize( = {}) # rubocop:disable Metrics/AbcSize [:projector] ||= {} self.autostart = .fetch(:autostart, true) self.autofinish = .fetch(:autofinish, true) self.finished = false self.timer = Timer.new() projector_opts = if [:projector].any? [:projector] elsif [:smoothing] warn SMOOTHING_DEPRECATION_WARNING { :strength => [:smoothing] } elsif [:running_average_rate] warn RUNNING_AVERAGE_RATE_DEPRECATION_WARNING { :strength => [:smoothing] } else {} end self.projector = Projector. from_type([:projector][:type]). new(projector_opts) self.progressable = Progress.new() = .merge(:progress => progressable, :projector => projector, :timer => timer) self.title_component = Components::Title.new() self. = Components::Bar.new() self.percentage_component = Components::Percentage.new() self.rate_component = Components::Rate.new() self.time_component = 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
137 138 139 |
# File 'lib/ruby-progressbar/base.rb', line 137 def decrement update_progress(:decrement) end |
#finish ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby-progressbar/base.rb', line 92 def finish return if finished? output.with_refresh do self.finished = true progressable.finish timer.stop end end |
#finished? ⇒ Boolean
129 130 131 |
# File 'lib/ruby-progressbar/base.rb', line 129 def finished? finished || (autofinish && progressable.finished?) end |
#format=(other) ⇒ Object Also known as: format
203 204 205 206 207 |
# File 'lib/ruby-progressbar/base.rb', line 203 def format=(other) output.refresh_with_format_change do @format = Format::String.new(other || output.default_format) end end |
#increment ⇒ Object
141 142 143 |
# File 'lib/ruby-progressbar/base.rb', line 141 def increment update_progress(:increment) end |
#inspect ⇒ Object
rubocop:enable Metrics/AbcSize, Layout/LineLength
199 200 201 |
# File 'lib/ruby-progressbar/base.rb', line 199 def inspect "#<ProgressBar:#{progress}/#{total || 'unknown'}>" end |
#pause ⇒ Object
102 103 104 |
# File 'lib/ruby-progressbar/base.rb', line 102 def pause output.with_refresh { timer.pause } unless paused? end |
#progress=(new_progress) ⇒ Object
145 146 147 |
# File 'lib/ruby-progressbar/base.rb', line 145 def progress=(new_progress) update_progress(:progress=, new_progress) end |
#progress_mark=(mark) ⇒ Object
153 154 155 |
# File 'lib/ruby-progressbar/base.rb', line 153 def progress_mark=(mark) output.refresh_with_format_change { .progress_mark = mark } end |
#remainder_mark=(mark) ⇒ Object
157 158 159 |
# File 'lib/ruby-progressbar/base.rb', line 157 def remainder_mark=(mark) output.refresh_with_format_change { .remainder_mark = mark } end |
#reset ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/ruby-progressbar/base.rb', line 114 def reset output.with_refresh do self.finished = false progressable.reset projector.reset timer.reset end end |
#resume ⇒ Object
110 111 112 |
# File 'lib/ruby-progressbar/base.rb', line 110 def resume output.with_refresh { timer.resume } if stopped? end |
#start(options = {}) ⇒ Object
87 88 89 90 |
# File 'lib/ruby-progressbar/base.rb', line 87 def start( = {}) timer.start update_progress(:start, ) end |
#started? ⇒ Boolean
133 134 135 |
# File 'lib/ruby-progressbar/base.rb', line 133 def started? timer.started? end |
#stop ⇒ Object
106 107 108 |
# File 'lib/ruby-progressbar/base.rb', line 106 def stop output.with_refresh { timer.stop } unless stopped? end |
#stopped? ⇒ Boolean Also known as: paused?
123 124 125 |
# File 'lib/ruby-progressbar/base.rb', line 123 def stopped? timer.stopped? || finished? end |
#title ⇒ Object
161 162 163 |
# File 'lib/ruby-progressbar/base.rb', line 161 def title title_component.title end |
#title=(title) ⇒ Object
165 166 167 |
# File 'lib/ruby-progressbar/base.rb', line 165 def title=(title) output.refresh_with_format_change { title_component.title = title } end |
#to_h ⇒ Object
rubocop:disable Metrics/AbcSize, Layout/LineLength
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ruby-progressbar/base.rb', line 176 def to_h { 'output_stream' => output.__send__(:stream), 'length' => output.length, 'title' => title_component.title, 'progress_mark' => .progress_mark, 'remainder_mark' => .remainder_mark, 'progress' => progressable.progress, 'total' => progressable.total, 'percentage' => progressable.percentage_completed_with_precision.to_f, 'elapsed_time_in_seconds' => time_component.__send__(:timer).elapsed_seconds, 'estimated_time_remaining_in_seconds' => time_component.__send__(:estimated_seconds_remaining), 'base_rate_of_change' => rate_component.__send__(:base_rate), 'scaled_rate_of_change' => rate_component.__send__(:scaled_rate), 'unknown_progress_animation_steps' => .upa_steps, 'throttle_rate' => output.__send__(:throttle).rate, 'started?' => started?, 'stopped?' => stopped?, 'finished?' => finished? } end |
#to_s(new_format = nil) ⇒ Object
169 170 171 172 173 |
# File 'lib/ruby-progressbar/base.rb', line 169 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
149 150 151 |
# File 'lib/ruby-progressbar/base.rb', line 149 def total=(new_total) update_progress(:total=, new_total) end |