Class: TTY::ProgressBar::Pipeline Private

Inherits:
Object
  • Object
show all
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

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

Examples:

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

Parameters:

  • tokenized (String)

    the string with tokens

Returns:

  • (nil)

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

Examples:

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

25
26
27
# File 'lib/tty/progressbar/pipeline.rb', line 25

def use(formatter)
  formatters << formatter
end