class TTY::ProgressBar::Configuration
Attributes
The preconfigured bar format name, defaults to :classic @api public
Whether or not to clear the progress line, defaults to false @api public
Whether or not to replace head character with complete, defaults to false @api public
The complete character in progress animation @api public
The frequency with which to display a progress bar per second @api public
The head character, defaults to complete @api public
Whether or not to hide the cursor, defaults to false @api public
The incomplete character in progress animation @api public
The amount of indentation before a progress animation @api private
The time interval for sampling of speed measurement, defaults to 1 second @api public
The object that responds to print call, defaults to stderr @api public
The total number of steps to completion @api public
The unknown character for indeterminate progress animation @api public
The maximum width for the progress bar except all formatting tokens @api public
Public Class Methods
# File lib/tty/progressbar/configuration.rb, line 66 def initialize(options) self.total = options[:total] if options[:total] @width = options.fetch(:width) { total } @bar_format = options.fetch(:bar_format, :classic) self.incomplete = options.fetch(:incomplete) { fetch_char(@bar_format, :incomplete) } self.complete = options.fetch(:complete) { fetch_char(@bar_format, :complete) } self.unknown = options.fetch(:unknown) { fetch_char(@bar_format, :unknown) } @head = options.fetch(:head) { @complete || "=" } @clear_head = options.fetch(:clear_head, false) @hide_cursor = options.fetch(:hide_cursor, false) @clear = options.fetch(:clear, false) @output = options.fetch(:output) { $stderr } @frequency = options.fetch(:frequency, 0) # 0Hz @interval = options.fetch(:interval, 1) # 1 sec @inset = options.fetch(:inset, 0) end
Public Instance Methods
Set complete character(s)
@param [String] value
@api public
# File lib/tty/progressbar/configuration.rb, line 88 def complete=(value) raise_if_empty(:complete, value) @complete = value end
Set incomplete character(s)
@param [String] value
@api public
# File lib/tty/progressbar/configuration.rb, line 99 def incomplete=(value) raise_if_empty(:incomplete, value) @incomplete = value end
Set total and adjust width if unset
@param [Integer,nil] value
@api public
# File lib/tty/progressbar/configuration.rb, line 121 def total=(value) @total = value self.width = value if width.nil? end
Set unknown character(s)
@param [String] value
@api public
# File lib/tty/progressbar/configuration.rb, line 110 def unknown=(value) raise_if_empty(:unknown, value) @unknown = value end
Private Instance Methods
Find bar char by type name and property
@param [Symbol] name @param [Symbol] property
@api private
# File lib/tty/progressbar/configuration.rb, line 134 def fetch_char(name, property) if FORMATS.key?(name) FORMATS[name][property] else raise ArgumentError, "unsupported bar format: #{name.inspect}. " \ "Available formats are: " \ "#{FORMATS.keys.sort.map(&:inspect).join(', ')}" end end
Check whether a parameter's value is empty or not
@raise [ArgumentError]
@api private
# File lib/tty/progressbar/configuration.rb, line 149 def raise_if_empty(name, value) return value unless value.to_s.empty? raise ArgumentError, "cannot provide an empty string for #{name.inspect}" end