lib/tty/progressbar/formatter/total.rb in tty-progressbar-0.17.0 vs lib/tty/progressbar/formatter/total.rb in tty-progressbar-0.18.0

- old
+ new

@@ -1,31 +1,25 @@ # frozen_string_literal: true +require_relative "../formatter" + module TTY class ProgressBar # Used by {Pipeline} to format :total token # # @api private class TotalFormatter - MATCHER = /:total\b/i.freeze + include TTY::ProgressBar::Formatter[/:total\b/i.freeze] - def initialize(progress, *args, &block) - @progress = progress - end - - # Determines whether this formatter is applied or not. + # Format :total token # - # @param [Object] value + # @param [String] value + # the value to format # - # @return [Boolean] - # - # @api private - def matches?(value) - !!(value.to_s =~ MATCHER) - end - - def format(value) - value.gsub(MATCHER, @progress.total.to_s) + # @api public + def call(value) + display = @progress.indeterminate? ? "-" : @progress.total.to_s + value.gsub(matcher, display) end end # TotalFormatter end # ProgressBar end # TTY