Sha256: eb503b18803c61a7a5afc359876f7ff37e505280a00749cf6f05c4f6c6132165

Contents?: true

Size: 851 Bytes

Versions: 7

Compression:

Stored size: 851 Bytes

Contents

# coding: utf-8

module TTY
  class ProgressBar
    # Used by {Pipeline} to format :mean_byte token
    #
    # @api private
    class MeanByteFormatter
      MATCHER = /:mean_byte/i.freeze

      def initialize(progress)
        @progress  = progress
        @converter = Converter.new
      end

      # Determines whether this formatter is applied or not.
      #
      # @param [Object] value
      #
      # @return [Boolean]
      #
      # @api private
      def matches?(value)
        !!(value.to_s =~ MATCHER)
      end

      # Format :rate token
      #
      # @param [String] value
      #  the value being formatted
      #
      # @api public
      def format(value)
        formatted = @converter.to_bytes(@progress.mean_rate)
        value.gsub(MATCHER, formatted)
      end
    end # MeanByteFormatter
  end # ProgressBar
end # TTY

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tty-progressbar-0.10.1 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.10.0 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.9.0 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.8.1 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.8.0 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.7.0 lib/tty/progressbar/formatter/mean_byte.rb
tty-progressbar-0.6.0 lib/tty/progressbar/formatter/mean_byte.rb