Class: CLIProgressBar::PercentProgressBar

Inherits:
ProgressBar
  • Object
show all
Defined in:
lib/cli_progress_bar/percent_progress_bar.rb

Instance Attribute Summary

Attributes inherited from ProgressBar

#progress

Instance Method Summary collapse

Constructor Details

#initialize(of: "", log_at: LOG_AT_TEN_PERCENTS, bar_length: BAR_LENGTH, line_char: LINE_CHAR, prefix: "", suffix: "", stream: STD_OUT) ⇒ PercentProgressBar

Returns a new instance of PercentProgressBar.



6
7
8
9
10
11
# File 'lib/cli_progress_bar/percent_progress_bar.rb', line 6

def initialize(
  of: "", log_at: LOG_AT_TEN_PERCENTS, bar_length: BAR_LENGTH,
  line_char: LINE_CHAR, prefix: "", suffix: "", stream: STD_OUT
)
  super
end

Instance Method Details

#increment(by: 1, prefix: nil, suffix: nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/cli_progress_bar/percent_progress_bar.rb', line 13

def increment(by: 1, prefix: nil, suffix: nil)
  raise "Invalid by: value" unless (@progress + by).between?(1, 100)

  @progress += by
  write_to_stream(prefix:, suffix:)
end

#update(percent, prefix: nil, suffix: nil) ⇒ Object



20
21
22
23
24
25
# File 'lib/cli_progress_bar/percent_progress_bar.rb', line 20

def update(percent, prefix: nil, suffix: nil)
  raise "Invalid percent value" unless percent.between?(1, 100)

  @progress = percent
  write_to_stream(prefix:, suffix:)
end