Class: NHKore::NoProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/nhkore/app.rb

Overview

Author:

  • Jonathan Bradley Whited

Since:

  • 0.2.0

Constant Summary collapse

MSG =

Since:

  • 0.2.0

'%{title}... %{percent}%%'
PUT_INTERVAL =

Since:

  • 0.2.0

100.0 / 6.25
MAX_PUT_INTERVAL =

Since:

  • 0.2.0

100.0 + PUT_INTERVAL + 1.0

Instance Method Summary collapse

Constructor Details

#initialize(title, total:, **tokens) ⇒ NoProgressBar

Returns a new instance of NoProgressBar.

Since:

  • 0.2.0



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

Since:

  • 0.2.0



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

#finishObject

Since:

  • 0.2.0



633
634
635
# File 'lib/nhkore/app.rb', line 633

def finish
  advance(@tokens[:total])
end

#resetObject

Since:

  • 0.2.0



598
599
600
601
602
# File 'lib/nhkore/app.rb', line 598

def reset
  @tokens[:advance] = 0
  @tokens[:percent] = 0
  @tokens[:progress] = 0
end

#startObject

Since:

  • 0.2.0



637
638
639
# File 'lib/nhkore/app.rb', line 637

def start
  puts to_s
end

#to_sObject

Since:

  • 0.2.0



641
642
643
# File 'lib/nhkore/app.rb', line 641

def to_s
  return MSG % @tokens
end