CoolFace
Apppublic

Rovatiana/LearnPulse

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes
command_line_progress.rb39 linesDownload Raw Back to lib
1class CommandLineProgress2  def initialize(max)3    @max = max4    @current = 05    @percentage = 06 7    puts "Starting processing of #{@max} entries..." if @max.positive? # rubocop:disable Rails/Output8  end9 10  def current_string_length11    @current_string_length ||= @max.to_s.length12  end13 14  def tick15    @current += 116    changed = compute_percentage17    inform_progress if changed18  end19 20  def compute_percentage21    new_percentage = (@current / @max.to_f) * 100.022 23    if new_percentage - @percentage >= 10.024      @percentage += 1025      true26    else27      false28    end29  end30 31  def inform_progress32    if @percentage.to_i == 10033      puts 'Processing complete!' # rubocop:disable Rails/Output34    else35      puts "Progress: #{@percentage}% [ #{@current.to_s.rjust(current_string_length, ' ')}/#{@max} ]" # rubocop:disable Rails/Output36    end37  end38end39