Sha256: c6649784a3e2750aecc8b1177c875ee278cc83133e0df1b11f6ad8a9ab473934

Contents?: true

Size: 864 Bytes

Versions: 6

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

require_relative '../converter'

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

      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 :rate token
      #
      # @param [String] value
      #  the value being formatted
      #
      # @api public
      def format(value)
        formatted = Converter.to_seconds(@progress.mean_rate)
        value.gsub(MATCHER, formatted)
      end
    end # MeanRateFormatter
  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/mean_rate.rb
tty-progressbar-0.16.0 lib/tty/progressbar/formatter/mean_rate.rb
tty-progressbar-0.15.1 lib/tty/progressbar/formatter/mean_rate.rb
tty-progressbar-0.15.0 lib/tty/progressbar/formatter/mean_rate.rb
tty-progressbar-0.14.0 lib/tty/progressbar/formatter/mean_rate.rb
tty-progressbar-0.13.0 lib/tty/progressbar/formatter/mean_rate.rb