Class: TTY::ProgressBar::MeanByteFormatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/progressbar/formatter/mean_byte.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 :mean_byte 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.

/:mean_byte/i.freeze

Instance Method Summary collapse

Constructor Details

#initialize(progress) ⇒ MeanByteFormatter

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 MeanByteFormatter.


13
14
15
# File 'lib/tty/progressbar/formatter/mean_byte.rb', line 13

def initialize(progress)
  @progress  = progress
end

Instance Method Details

#format(value) ⇒ Object

Format :rate token

Parameters:

  • value (String)

    the value being formatted


34
35
36
37
# File 'lib/tty/progressbar/formatter/mean_byte.rb', line 34

def format(value)
  formatted = Converter.to_bytes(@progress.mean_rate)
  value.gsub(MATCHER, formatted)
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)

24
25
26
# File 'lib/tty/progressbar/formatter/mean_byte.rb', line 24

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