Class: ConsoleProgressBar::Bar
- Inherits:
-
Object
- Object
- ConsoleProgressBar::Bar
- Includes:
- Extras, PrintTools
- Defined in:
- lib/console_progress_bar/bar.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(total_count = 100, with_elapsed_time = false, with_remaining_time = false, increment_size = 1, width = 20) ⇒ Bar
constructor
A new instance of Bar.
Constructor Details
#initialize(total_count = 100, with_elapsed_time = false, with_remaining_time = false, increment_size = 1, width = 20) ⇒ Bar
Returns a new instance of Bar.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/console_progress_bar/bar.rb', line 5 def initialize(total_count = 100, with_elapsed_time = false, with_remaining_time = false, increment_size = 1, width = 20) @total = total_count @current = 0 @recent = -1 @width = width @increment_size = increment_size @output = "|" @width.times do @output += " " end @output += "|" @with_elapsed_time = with_elapsed_time @with_remaining_time = with_remaining_time @start = Time.now @prev_time = Time.now @avarage_inceament_time = 0 @prev_extra_length = 0 @output_length = 0 end |
Instance Method Details
#draw ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/console_progress_bar/bar.rb', line 25 def draw @current += @increment_size if @current >= @total finished else @now = (@current * 1.0 / @total * @width).to_i if @recent != @now @recent = @now shift_back(@output_length + @prev_extra_length) @prev_extra_length = 0 @output = "|" @now.times do @output += "#" end (@width - @now).times do @output += " " end @output += "|" print @output @output_length = @output.length end prepare_extras end end |