class TTY::ProgressBar::Configuration

Attributes

bar_format[RW]

The preconfigured bar format name, defaults to :classic @api public

clear[RW]

Whether or not to clear the progress line, defaults to false @api public

clear_head[RW]

Whether or not to replace head character with complete, defaults to false @api public

complete[R]

The complete character in progress animation @api public

frequency[RW]

The frequency with which to display a progress bar per second @api public

head[RW]

The head character, defaults to complete @api public

hide_cursor[RW]

Whether or not to hide the cursor, defaults to false @api public

incomplete[R]

The incomplete character in progress animation @api public

inset[RW]

The amount of indentation before a progress animation @api private

interval[RW]

The time interval for sampling of speed measurement, defaults to 1 second @api public

output[RW]

The object that responds to print call, defaults to stderr @api public

total[R]

The total number of steps to completion @api public

unknown[R]

The unknown character for indeterminate progress animation @api public

width[RW]

The maximum width for the progress bar except all formatting tokens @api public

Public Class Methods

new(options) click to toggle source
# 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

complete=(value) click to toggle source

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
incomplete=(value) click to toggle source

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
total=(value) click to toggle source

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
unknown=(value) click to toggle source

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

fetch_char(name, property) click to toggle source

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
raise_if_empty(name, value) click to toggle source

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