Class: ProgressBar::Bar
- Inherits:
-
Object
- Object
- ProgressBar::Bar
- Defined in:
- lib/progress-bar/bar.rb
Constant Summary collapse
- DEFAULT_OUTPUT_STREAM =
$stdout- DEFAULT_LENGTH =
100
Instance Attribute Summary collapse
-
#format_string ⇒ Object
Returns the value of attribute format_string.
-
#length ⇒ Object
Returns the value of attribute length.
-
#output ⇒ Object
Returns the value of attribute output.
-
#steps ⇒ Object
Returns the value of attribute steps.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Bar
constructor
A new instance of Bar.
- #result ⇒ Object
- #step(sym) ⇒ Object
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( = {}) @output = [:output] || DEFAULT_OUTPUT_STREAM @length = [:length] || DEFAULT_LENGTH @steps = [:steps] || 1 init_string update(@output, @format_string) end |
Instance Attribute Details
#format_string ⇒ Object
Returns the value of attribute format_string.
7 8 9 |
# File 'lib/progress-bar/bar.rb', line 7 def format_string @format_string end |
#length ⇒ Object
Returns the value of attribute length.
7 8 9 |
# File 'lib/progress-bar/bar.rb', line 7 def length @length end |
#output ⇒ Object
Returns the value of attribute output.
7 8 9 |
# File 'lib/progress-bar/bar.rb', line 7 def output @output end |
#steps ⇒ Object
Returns the value of attribute steps.
7 8 9 |
# File 'lib/progress-bar/bar.rb', line 7 def steps @steps end |
Instance Method Details
#result ⇒ Object
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 |