Class: Omnizip::Progress::OperationProgress
- Inherits:
-
Object
- Object
- Omnizip::Progress::OperationProgress
- Defined in:
- lib/omnizip/progress/operation_progress.rb
Overview
Represents the current state of an operation's progress.
This class stores all data about the current progress of an operation, including file counts, byte counts, current file being processed, and calculated percentages.
Instance Attribute Summary collapse
-
#bytes_done ⇒ Object
readonly
Returns the value of attribute bytes_done.
-
#current_file ⇒ Object
readonly
Returns the value of attribute current_file.
-
#files_done ⇒ Object
readonly
Returns the value of attribute files_done.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#total_bytes ⇒ Object
readonly
Returns the value of attribute total_bytes.
-
#total_files ⇒ Object
readonly
Returns the value of attribute total_files.
Instance Method Summary collapse
-
#bytes_percent ⇒ Float
Calculate percentage of bytes complete.
-
#complete? ⇒ Boolean
Check if operation is complete.
-
#elapsed_seconds ⇒ Float
Get elapsed time in seconds.
-
#files_percent ⇒ Float
Calculate percentage of files complete.
-
#initialize(total_files:, total_bytes:) ⇒ OperationProgress
constructor
Initialize a new operation progress tracker.
-
#percentage ⇒ Float
Calculate overall percentage complete.
-
#remaining_bytes ⇒ Integer
Get remaining bytes to process.
-
#remaining_files ⇒ Integer
Get remaining files to process.
-
#to_h ⇒ Hash
Get progress as hash for serialization.
-
#update(files:, bytes:, current_file: nil) ⇒ Object
Update progress with new values.
Constructor Details
#initialize(total_files:, total_bytes:) ⇒ OperationProgress
Initialize a new operation progress tracker
22 23 24 25 26 27 28 29 |
# File 'lib/omnizip/progress/operation_progress.rb', line 22 def initialize(total_files:, total_bytes:) @total_files = total_files @total_bytes = total_bytes @files_done = 0 @bytes_done = 0 @current_file = nil @start_time = Time.now end |
Instance Attribute Details
#bytes_done ⇒ Object (readonly)
Returns the value of attribute bytes_done.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def bytes_done @bytes_done end |
#current_file ⇒ Object (readonly)
Returns the value of attribute current_file.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def current_file @current_file end |
#files_done ⇒ Object (readonly)
Returns the value of attribute files_done.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def files_done @files_done end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def start_time @start_time end |
#total_bytes ⇒ Object (readonly)
Returns the value of attribute total_bytes.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def total_bytes @total_bytes end |
#total_files ⇒ Object (readonly)
Returns the value of attribute total_files.
15 16 17 |
# File 'lib/omnizip/progress/operation_progress.rb', line 15 def total_files @total_files end |
Instance Method Details
#bytes_percent ⇒ Float
Calculate percentage of bytes complete
63 64 65 66 67 |
# File 'lib/omnizip/progress/operation_progress.rb', line 63 def bytes_percent return 0.0 if total_bytes.zero? (bytes_done.to_f / total_bytes * 100.0).round(1) end |
#complete? ⇒ Boolean
Check if operation is complete
93 94 95 |
# File 'lib/omnizip/progress/operation_progress.rb', line 93 def complete? files_done >= total_files && bytes_done >= total_bytes end |
#elapsed_seconds ⇒ Float
Get elapsed time in seconds
72 73 74 |
# File 'lib/omnizip/progress/operation_progress.rb', line 72 def elapsed_seconds Time.now - start_time end |
#files_percent ⇒ Float
Calculate percentage of files complete
54 55 56 57 58 |
# File 'lib/omnizip/progress/operation_progress.rb', line 54 def files_percent return 0.0 if total_files.zero? (files_done.to_f / total_files * 100.0).round(1) end |
#percentage ⇒ Float
Calculate overall percentage complete
45 46 47 48 49 |
# File 'lib/omnizip/progress/operation_progress.rb', line 45 def percentage return 0.0 if total_bytes.zero? (bytes_done.to_f / total_bytes * 100.0).round(1) end |
#remaining_bytes ⇒ Integer
Get remaining bytes to process
79 80 81 |
# File 'lib/omnizip/progress/operation_progress.rb', line 79 def remaining_bytes total_bytes - bytes_done end |
#remaining_files ⇒ Integer
Get remaining files to process
86 87 88 |
# File 'lib/omnizip/progress/operation_progress.rb', line 86 def remaining_files total_files - files_done end |
#to_h ⇒ Hash
Get progress as hash for serialization
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/omnizip/progress/operation_progress.rb', line 100 def to_h { total_files: total_files, total_bytes: total_bytes, files_done: files_done, bytes_done: bytes_done, current_file: current_file, percentage: percentage, files_percent: files_percent, bytes_percent: bytes_percent, elapsed_seconds: elapsed_seconds, remaining_bytes: remaining_bytes, remaining_files: remaining_files, complete: complete?, } end |
#update(files:, bytes:, current_file: nil) ⇒ Object
Update progress with new values
36 37 38 39 40 |
# File 'lib/omnizip/progress/operation_progress.rb', line 36 def update(files:, bytes:, current_file: nil) @files_done = files @bytes_done = bytes @current_file = current_file end |