Sha256: d0e31624086d1ebdb3cbea5ef3502a751e8eeb61dfb0d87769271396515f7245

Contents?: true

Size: 780 Bytes

Versions: 6

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

module TTY
  class ProgressBar
    # Used by {Pipeline} to format :current token
    #
    # @api private
    class CurrentFormatter
      MATCHER = /:current\b/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 :current token
      #
      # @param [String] value
      #  the value being formatted
      #
      # @api public
      def format(value)
        value.gsub(MATCHER, @progress.current.to_s)
      end
    end # CurrentFormatter
  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/current.rb
tty-progressbar-0.16.0 lib/tty/progressbar/formatter/current.rb
tty-progressbar-0.15.1 lib/tty/progressbar/formatter/current.rb
tty-progressbar-0.15.0 lib/tty/progressbar/formatter/current.rb
tty-progressbar-0.14.0 lib/tty/progressbar/formatter/current.rb
tty-progressbar-0.13.0 lib/tty/progressbar/formatter/current.rb