Sha256: 22ad506b7ffda9215b9d86aefefc940e631d3f9100989fed7bbcf0e62a768d07

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

# coding: utf-8

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

      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

1 entries across 1 versions & 1 rubygems

Version Path
tty-progressbar-0.3.0 lib/tty/progressbar/formatter/current.rb