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