class Numeric

@author {cuihaiqin@gmail.com cuihq}

Public Instance Methods

process_bar(width = IO.width - 8) click to toggle source

get process bar.

@example process bar

print i.process_bar

@param width [Integer] process width @return [String] process bar

# File lib/term/process_bar.rb, line 13
def process_bar(width = IO.width - 8)
  percent = format(' %3d%', self)
  line = '-' * width
  if self <= 0
    "[#{line.insert(0, '🛫')}]#{percent}"
  elsif self >= 100
    "[#{line.insert(-1, '🛬')}]#{percent}"
  else
    "[#{line.insert((self / 100.0 * width).to_i, '✈️')}]#{percent}"
  end
end