Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/term/process_bar.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#process_bar(width = IO.width - 8) ⇒ String

get process bar.

Examples:

process bar

print i.process_bar

Parameters:

  • width (Integer) (defaults to: IO.width - 8)

    process width

Returns:



13
14
15
16
17
18
19
20
21
22
23
# 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