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
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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby-progressbar/base.rb', line 28 def initialize( = {}) # rubocop:disable Metrics/AbcSize self.autostart = .fetch(:autostart, true) self.autofinish = .fetch(:autofinish, true) self.finished = false self.timer = Timer.new() self.progressable = Progress.new() = .merge(:progress => progressable, :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
100 101 102 |
# File 'lib/ruby-progressbar/base.rb', line 100 def decrement update_progress(:decrement) end |
#finish ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/ruby-progressbar/base.rb', line 56 def finish return if finished? output.with_refresh do self.finished = true progressable.finish timer.stop end end |
#finished? ⇒ Boolean
92 93 94 |
# File 'lib/ruby-progressbar/base.rb', line 92 def finished? finished || (autofinish && progressable.finished?) end |
#format=(other) ⇒ Object Also known as: format
166 167 168 169 170 |
# File 'lib/ruby-progressbar/base.rb', line 166 def format=(other) output.refresh_with_format_change do @format = Format::String.new(other || output.default_format) end end |
#increment ⇒ Object
104 105 106 |
# File 'lib/ruby-progressbar/base.rb', line 104 def increment update_progress(:increment) end |
#inspect ⇒ Object
rubocop:enable Metrics/AbcSize, Layout/LineLength
162 163 164 |
# File 'lib/ruby-progressbar/base.rb', line 162 def inspect "#<ProgressBar:#{progress}/#{total || 'unknown'}>" end |
#pause ⇒ Object
66 67 68 |
# File 'lib/ruby-progressbar/base.rb', line 66 def pause output.with_refresh { timer.pause } unless paused? end |
#progress=(new_progress) ⇒ Object
108 109 110 |
# File 'lib/ruby-progressbar/base.rb', line 108 def progress=(new_progress) update_progress(:progress=, new_progress) end |
#progress_mark=(mark) ⇒ Object
116 117 118 |
# File 'lib/ruby-progressbar/base.rb', line 116 def progress_mark=(mark) output.refresh_with_format_change { .progress_mark = mark } end |
#remainder_mark=(mark) ⇒ Object
120 121 122 |
# File 'lib/ruby-progressbar/base.rb', line 120 def remainder_mark=(mark) output.refresh_with_format_change { .remainder_mark = mark } end |
#reset ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/ruby-progressbar/base.rb', line 78 def reset output.with_refresh do self.finished = false progressable.reset timer.reset end end |
#resume ⇒ Object
74 75 76 |
# File 'lib/ruby-progressbar/base.rb', line 74 def resume output.with_refresh { timer.resume } if stopped? end |
#start(options = {}) ⇒ Object
51 52 53 54 |
# File 'lib/ruby-progressbar/base.rb', line 51 def start( = {}) timer.start update_progress(:start, ) end |
#started? ⇒ Boolean
96 97 98 |
# File 'lib/ruby-progressbar/base.rb', line 96 def started? timer.started? end |
#stop ⇒ Object
70 71 72 |
# File 'lib/ruby-progressbar/base.rb', line 70 def stop output.with_refresh { timer.stop } unless stopped? end |
#stopped? ⇒ Boolean Also known as: paused?
86 87 88 |
# File 'lib/ruby-progressbar/base.rb', line 86 def stopped? timer.stopped? || finished? end |
#title ⇒ Object
124 125 126 |
# File 'lib/ruby-progressbar/base.rb', line 124 def title title_component.title end |
#title=(title) ⇒ Object
128 129 130 |
# File 'lib/ruby-progressbar/base.rb', line 128 def title=(title) output.refresh_with_format_change { title_component.title = title } end |
#to_h ⇒ Object
rubocop:disable Metrics/AbcSize, Layout/LineLength
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ruby-progressbar/base.rb', line 139 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
132 133 134 135 136 |
# File 'lib/ruby-progressbar/base.rb', line 132 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
112 113 114 |
# File 'lib/ruby-progressbar/base.rb', line 112 def total=(new_total) update_progress(:total=, new_total) end |