Class: ProgressBar::Bar

Inherits:
Object
  • Object
show all
Defined in:
lib/progress-bar/bar.rb

Constant Summary collapse

DEFAULT_OUTPUT_STREAM =
$stdout
DEFAULT_LENGTH =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Bar

Returns a new instance of Bar.



9
10
11
12
13
14
15
16
# File 'lib/progress-bar/bar.rb', line 9

def initialize(options = {})
  @output = options[:output] || DEFAULT_OUTPUT_STREAM
  @length = options[:length] || DEFAULT_LENGTH
  @steps = options[:steps] || 1
  init_string

  update(@output, @format_string)
end

Instance Attribute Details

#format_stringObject

Returns the value of attribute format_string.



7
8
9
# File 'lib/progress-bar/bar.rb', line 7

def format_string
  @format_string
end

#lengthObject

Returns the value of attribute length.



7
8
9
# File 'lib/progress-bar/bar.rb', line 7

def length
  @length
end

#outputObject

Returns the value of attribute output.



7
8
9
# File 'lib/progress-bar/bar.rb', line 7

def output
  @output
end

#stepsObject

Returns the value of attribute steps.



7
8
9
# File 'lib/progress-bar/bar.rb', line 7

def steps
  @steps
end

Instance Method Details

#resultObject



23
24
25
26
# File 'lib/progress-bar/bar.rb', line 23

def result
  output.print @format_string
  output.flush
end

#step(sym) ⇒ Object



18
19
20
21
# File 'lib/progress-bar/bar.rb', line 18

def step sym
  @format_string += "#{'=' * (step_length - 1) + sym}"
  update @output, @format_string
end