Class: ProgressBarView

Inherits:
Object
  • Object
show all
Includes:
TerminalUtils
Defined in:
lib/views.rb

Constant Summary collapse

EXTRA_CHARS_OFFSET =

brackets, % completion

8
USABLE_WIDTH =
SCREEN_WIDTH - EXTRA_CHARS_OFFSET

Constants included from TerminalUtils

TerminalUtils::ERASE_DISPLAY, TerminalUtils::GREEN, TerminalUtils::RED, TerminalUtils::RESET, TerminalUtils::RESTORE_CURSOR, TerminalUtils::SAVE_CURSOR, TerminalUtils::SCREEN_WIDTH

Instance Method Summary collapse

Constructor Details

#initialize(percent) ⇒ ProgressBarView

Returns a new instance of ProgressBarView.



35
36
37
# File 'lib/views.rb', line 35

def initialize(percent)
  @percent = Float([percent, 100.0].min)
end

Instance Method Details

#to_sObject



39
40
41
42
43
# File 'lib/views.rb', line 39

def to_s
  complete = '#' * ((@percent / 100.0) * USABLE_WIDTH).to_i
  incomplete = ' ' * (USABLE_WIDTH - complete.length)
  [GREEN, ' [', complete, incomplete, ']', (@percent.to_i.to_s + '%').rjust(5), RESET].join
end