Class: TTY::ProgressBar::Pipeline Private
- Inherits:
-
Object
- Object
- TTY::ProgressBar::Pipeline
- Includes:
- Enumerable
- Defined in:
- lib/tty/progressbar/pipeline.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 TTY::ProgressBar to decorate format string
Instance Method Summary collapse
-
#decorate(tokenized) ⇒ nil
private
Decorate the tokenized string with actual values.
-
#each(&block) ⇒ Object
Iterate over formatters.
-
#initialize(formatters = []) ⇒ Pipeline
constructor
private
Create formatting pipeline.
-
#use(formatter) ⇒ Object
Add a new formatter.
Constructor Details
#initialize(formatters = []) ⇒ Pipeline
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.
Create formatting pipeline
14 15 16 17 |
# File 'lib/tty/progressbar/pipeline.rb', line 14 def initialize(formatters = []) @formatters = formatters freeze end |
Instance Method Details
#decorate(tokenized) ⇒ nil
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.
Decorate the tokenized string with actual values
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tty/progressbar/pipeline.rb', line 40 def decorate(tokenized) base = tokenized.dup formatters.inject(base) do |formatted, formatter| if formatter.respond_to?(:matches?) && formatter.matches?(formatted) formatter.(formatted) else formatted end end end |
#each(&block) ⇒ Object
Iterate over formatters
54 55 56 |
# File 'lib/tty/progressbar/pipeline.rb', line 54 def each(&block) formatters.each(&block) end |
#use(formatter) ⇒ Object
Add a new formatter
25 26 27 |
# File 'lib/tty/progressbar/pipeline.rb', line 25 def use(formatter) formatters << formatter end |