Class: TTY::ProgressBar::PercentFormatter Private
- Inherits:
-
Object
- Object
- TTY::ProgressBar::PercentFormatter
- 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
- #format(value) ⇒ Object private
-
#initialize(progress, *args, &block) ⇒ PercentFormatter
constructor
private
A new instance of PercentFormatter.
-
#matches?(value) ⇒ Boolean
private
Determines whether this formatter is applied or not.
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.
22 23 24 |
# File 'lib/tty/progressbar/formatter/percent.rb', line 22 def matches?(value) !!(value.to_s =~ MATCHER) end |