Class: Progress
- Inherits:
-
Object
- Object
- Progress
- Defined in:
- lib/progress.rb
Constant Summary collapse
- UNITS =
["B", "KiB", "MiB", "GiB"]
- SCALE =
1024.0
Instance Method Summary collapse
-
#initialize(output) ⇒ Progress
constructor
A new instance of Progress.
- #start(message, total = nil) ⇒ Object
- #stop ⇒ Object
- #tick(bytes = 0) ⇒ Object
Constructor Details
#initialize(output) ⇒ Progress
Returns a new instance of Progress.
5 6 7 8 |
# File 'lib/progress.rb', line 5 def initialize(output) @output = output @message = nil end |
Instance Method Details
#start(message, total = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/progress.rb', line 10 def start(, total = nil) return if ENV["NO_PROGRESS"] or not @output.isatty @message = @total = total @count = 0 @bytes = 0 @write_at = get_time end |
#stop ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/progress.rb', line 34 def stop return unless @message @total = @count clear_line @output.puts(status_line) @message = nil end |
#tick(bytes = 0) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/progress.rb', line 20 def tick(bytes = 0) return unless @message @count += 1 @bytes = bytes current_time = get_time return if current_time < @write_at + 0.05 @write_at = current_time clear_line @output.write(status_line) end |