Class: NHKore::NoProgressBar
- Inherits:
-
Object
- Object
- NHKore::NoProgressBar
- Defined in:
- lib/nhkore/app.rb
Overview
Constant Summary collapse
- MSG =
'%{title}... %{percent}%%'
- PUT_INTERVAL =
100.0 / 6.25
- MAX_PUT_INTERVAL =
100.0 + PUT_INTERVAL + 1.0
Instance Method Summary collapse
- #advance(progress = 1) ⇒ Object
- #finish ⇒ Object
-
#initialize(title, total:, **tokens) ⇒ NoProgressBar
constructor
A new instance of NoProgressBar.
- #reset ⇒ Object
- #start ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(title, total:, **tokens) ⇒ NoProgressBar
Returns a new instance of NoProgressBar.
588 589 590 591 592 593 594 595 596 |
# File 'lib/nhkore/app.rb', line 588 def initialize(title,total:,**tokens) super() @tokens = {title: title,total: total} reset @tokens.merge!(tokens) end |
Instance Method Details
#advance(progress = 1) ⇒ Object
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/nhkore/app.rb', line 604 def advance(progress=1) total = @tokens[:total] progress = @tokens[:progress] + progress progress = total if progress > total percent = (progress.to_f / total.to_f * 100.0).round @tokens[:percent] = percent @tokens[:progress] = progress if percent < 99.0 # Only output at certain intervals. advance = @tokens[:advance] i = 0.0 while i <= MAX_PUT_INTERVAL if advance < i break if percent >= i # Output return # Don't output end i += PUT_INTERVAL end end @tokens[:advance] = percent puts to_s end |
#finish ⇒ Object
633 634 635 |
# File 'lib/nhkore/app.rb', line 633 def finish advance(@tokens[:total]) end |
#reset ⇒ Object
598 599 600 601 602 |
# File 'lib/nhkore/app.rb', line 598 def reset @tokens[:advance] = 0 @tokens[:percent] = 0 @tokens[:progress] = 0 end |
#start ⇒ Object
637 638 639 |
# File 'lib/nhkore/app.rb', line 637 def start puts to_s end |