Class: Prog::Task
- Inherits:
-
Object
- Object
- Prog::Task
- Defined in:
- lib/prog.rb
Instance Attribute Summary collapse
-
#current_count ⇒ Object
Returns the value of attribute current_count.
-
#max_count ⇒ Object
Returns the value of attribute max_count.
-
#pipe ⇒ Object
Returns the value of attribute pipe.
-
#working_length ⇒ Object
Returns the value of attribute working_length.
Instance Method Summary collapse
- #force_finish ⇒ Object
-
#initialize(max_count:) ⇒ Task
constructor
A new instance of Task.
- #tick(number_of_ticks = 1) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(max_count:) ⇒ Task
Returns a new instance of Task.
58 59 60 61 62 |
# 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 |
Instance Attribute Details
#current_count ⇒ Object
Returns the value of attribute current_count.
55 56 57 |
# File 'lib/prog.rb', line 55 def current_count @current_count end |
#max_count ⇒ Object
Returns the value of attribute max_count.
55 56 57 |
# File 'lib/prog.rb', line 55 def max_count @max_count end |
#pipe ⇒ Object
Returns the value of attribute pipe.
55 56 57 |
# File 'lib/prog.rb', line 55 def pipe @pipe end |
#working_length ⇒ Object
Returns the value of attribute working_length.
56 57 58 |
# File 'lib/prog.rb', line 56 def working_length @working_length end |
Instance Method Details
#force_finish ⇒ Object
70 71 72 73 |
# 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) ⇒ Object
64 65 66 67 68 |
# 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 ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 = ('=' * filled_cells).ljust(unused_length, ' ') display_string.prepend() display_string end |