class TTY::ProgressBar::Pipeline

Used by {ProgressBar} to decorate format string

@api private

Attributes

formatters[R]

Public Class Methods

new(formatters = []) click to toggle source

Create formatting pipeline

@api private

# File lib/tty/progressbar/pipeline.rb, line 14
def initialize(formatters = [])
  @formatters = formatters
  freeze
end

Public Instance Methods

decorate(tokenized) click to toggle source

Decorate the tokenized string with actual values

@example

decorate("[:bar] :current :elapsed")

@param [String] tokenized

the string with tokens

@return [nil]

@api private

# 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) click to toggle source

Iterate over formatters

@api public

# File lib/tty/progressbar/pipeline.rb, line 54
def each(&block)
  formatters.each(&block)
end
use(formatter) click to toggle source

Add a new formatter

@example

use(TTY::ProgressBar::TotalFormatter.new(progress_bar))

@api public

# File lib/tty/progressbar/pipeline.rb, line 25
def use(formatter)
  formatters << formatter
end