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

Constant Summary collapse

MATCHER =

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

/:percent\b/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(progress, *args, &block) ⇒ PercentFormatter

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

Returns a new instance of PercentFormatter.



11
12
13
# File 'lib/tty/progressbar/formatter/percent.rb', line 11

def initialize(progress, *args, &block)
  @progress = progress
end

Instance Method Details

#format(value) ⇒ Object

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



26
27
28
29
# File 'lib/tty/progressbar/formatter/percent.rb', line 26

def format(value)
  percent = @progress.width == 0 ? 100 : (@progress.ratio * 100).to_i
  value.gsub(MATCHER, percent.to_s + '%')
end

#matches?(value) ⇒ Boolean

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

Determines whether this formatter is applied or not.

Parameters:

  • value (Object)

Returns:

  • (Boolean)


22
23
24
# File 'lib/tty/progressbar/formatter/percent.rb', line 22

def matches?(value)
  !!(value.to_s =~ MATCHER)
end