Class: ProgressMonitor::Display::ProgressBar
- Inherits:
-
Object
- Object
- ProgressMonitor::Display::ProgressBar
- Defined in:
- lib/progress_monitor/display/progress_bar.rb
Constant Summary collapse
- BAR_PROGRESS =
"█"- BAR_SPACE =
" "- BAR_PARTIAL_PROGRESS =
[BAR_SPACE, '▏', '▎', '▍', '▌', '▋', '▊', '▉']
Instance Attribute Summary collapse
-
#completion_percent ⇒ Object
Returns the value of attribute completion_percent.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(size: 20, completion_percent: 0) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #render ⇒ Object
Constructor Details
#initialize(size: 20, completion_percent: 0) ⇒ ProgressBar
Returns a new instance of ProgressBar.
6 7 8 9 |
# File 'lib/progress_monitor/display/progress_bar.rb', line 6 def initialize(size: 20, completion_percent: 0) @size = size @completion_percent = completion_percent end |
Instance Attribute Details
#completion_percent ⇒ Object
Returns the value of attribute completion_percent.
4 5 6 |
# File 'lib/progress_monitor/display/progress_bar.rb', line 4 def completion_percent @completion_percent end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/progress_monitor/display/progress_bar.rb', line 4 def size @size end |
Instance Method Details
#render ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/progress_monitor/display/progress_bar.rb', line 15 def render if completion_percent == :unknown '╍' * size else completion_float = completion_percent.to_f / 100 * size completion_size = completion_float.floor remainder = (completion_float % 1 * 8).floor if completion_size < size BAR_PROGRESS * completion_size + BAR_PARTIAL_PROGRESS[remainder] + BAR_SPACE * (size - completion_size - 1) else BAR_PROGRESS * size end end rescue => e puts e "" end |