Sha256: aefdded3948d5e3e23b7308d33d303babbff44c24bbac7e5f27bad83fb3e7292

Contents?: true

Size: 844 Bytes

Versions: 7

Compression:

Stored size: 844 Bytes

Contents

# coding: utf-8

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
        @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 :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

7 entries across 7 versions & 1 rubygems

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