Sha256: 16a62950a650f0014b659371bf5d297e8cad04e84e3bdded7098e4a5e7af50c6

Contents?: true

Size: 854 Bytes

Versions: 6

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true

require_relative '../converter'

module TTY
  class ProgressBar
    # Used by {Pipeline} to format :byte_rate token
    #
    # @api private
    class ByteRateFormatter
      MATCHER = /:byte_rate/i

      def initialize(progress)
        @progress = progress
      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 :byte_rate token
      #
      # @param [String] value
      #  the value being formatted
      #
      # @api public
      def format(value)
        formatted = Converter.to_bytes(@progress.rate)
        value.gsub(MATCHER, formatted)
      end
    end # ByteRateFormatter
  end # ProgressBar
end # TTY

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tty-progressbar-0.17.0 lib/tty/progressbar/formatter/byte_rate.rb
tty-progressbar-0.16.0 lib/tty/progressbar/formatter/byte_rate.rb
tty-progressbar-0.15.1 lib/tty/progressbar/formatter/byte_rate.rb
tty-progressbar-0.15.0 lib/tty/progressbar/formatter/byte_rate.rb
tty-progressbar-0.14.0 lib/tty/progressbar/formatter/byte_rate.rb
tty-progressbar-0.13.0 lib/tty/progressbar/formatter/byte_rate.rb