Class: TTY::ProgressBar::PercentFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/progressbar/formatter/percent.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Used by Pipeline to format :percent token

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ Object

Format :percent token

Parameters:

  • value (String)

    the value to format



19
20
21
22
23
# File 'lib/tty/progressbar/formatter/percent.rb', line 19

def call(value)
  percent = @progress.width == 0 ? 100 : (@progress.ratio * 100).to_i
  display = @progress.indeterminate? ? "-" : percent.to_s
  value.gsub(matcher, "#{display}%")
end