class Prog::Task

Attributes

current_count[RW]
max_count[RW]
pipe[RW]
working_length[RW]

Public Class Methods

new(max_count:) click to toggle source
# File lib/prog.rb, line 58
def initialize(max_count:)
  self.max_count = max_count
  self.current_count = 0
  self.working_length = nil # (Only set by Prog::Pipe)
end

Public Instance Methods

force_finish() click to toggle source
# File lib/prog.rb, line 70
def force_finish
  pipe.tasks.delete(self)
  pipe.highest_count = 0 if pipe.tasks.empty?
end
tick(number_of_ticks = 1) click to toggle source
# File lib/prog.rb, line 64
def tick(number_of_ticks = 1)
  self.current_count += number_of_ticks

  force_finish if current_count >= max_count
end
to_s() click to toggle source
# File lib/prog.rb, line 75
def to_s
  progress_ratio = current_count / max_count.to_f

  unused_length = working_length
  display_string = +'|' # (not frozen)
  unused_length -= 1

  filled_cells = (unused_length * progress_ratio).floor
  fill_bar = ('=' * filled_cells).ljust(unused_length, ' ')
  display_string.prepend(fill_bar)

  display_string
end