Class: NHKore::NoProgressBar
- Inherits:
-
Object
- Object
- NHKore::NoProgressBar
- Defined in:
- lib/nhkore/app.rb
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.
568 569 570 571 572 573 574 575 576 |
# File 'lib/nhkore/app.rb', line 568 def initialize(title,total:,**tokens) super() @tokens = {title: title,total: total} reset @tokens.merge!(tokens) end |
Instance Method Details
#advance(progress = 1) ⇒ Object
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/nhkore/app.rb', line 584 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 self end |
#finish ⇒ Object
613 614 615 |
# File 'lib/nhkore/app.rb', line 613 def finish advance(@tokens[:total]) end |
#reset ⇒ Object
578 579 580 581 582 |
# File 'lib/nhkore/app.rb', line 578 def reset @tokens[:advance] = 0 @tokens[:percent] = 0 @tokens[:progress] = 0 end |
#start ⇒ Object
617 618 619 |
# File 'lib/nhkore/app.rb', line 617 def start puts self end |
#to_s ⇒ Object
621 622 623 |
# File 'lib/nhkore/app.rb', line 621 def to_s return MSG % @tokens end |