Class: Evm::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/evm/progress_bar.rb

Constant Summary collapse

COLUMNS =
100

Instance Method Summary collapse

Constructor Details

#initializeProgressBar

Returns a new instance of ProgressBar.



5
6
7
# File 'lib/evm/progress_bar.rb', line 5

def initialize
  @started = false
end

Instance Method Details

#doneObject



33
34
35
# File 'lib/evm/progress_bar.rb', line 33

def done
  set 100
end

#set(progress) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/evm/progress_bar.rb', line 9

def set(progress)
  progress = progress.to_i

  if progress < 0 || progress > 100
    raise "Invalid progress #{progress}, must be between 0 and 100"
  end

  unless @started
    puts
    @started = true
  end

  print "\e[1A"
  print "\e[K"
  print '['
  print '-' * progress
  print ' ' * (COLUMNS - progress)
  print ']'
  print ' '
  print progress
  print '%'
  puts
end