Class: Archaeo::ProgressReport
- Inherits:
-
Struct
- Object
- Struct
- Archaeo::ProgressReport
- Defined in:
- lib/archaeo/progress_report.rb
Overview
Value object representing download progress at a point in time.
Provides computed metrics like percentage, speed, and ETA based on current counters and elapsed time.
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#current_url ⇒ Object
Returns the value of attribute current_url.
-
#downloaded_bytes ⇒ Object
Returns the value of attribute downloaded_bytes.
-
#elapsed ⇒ Object
Returns the value of attribute elapsed.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current
8 9 10 |
# File 'lib/archaeo/progress_report.rb', line 8 def current @current end |
#current_url ⇒ Object
Returns the value of attribute current_url
8 9 10 |
# File 'lib/archaeo/progress_report.rb', line 8 def current_url @current_url end |
#downloaded_bytes ⇒ Object
Returns the value of attribute downloaded_bytes
8 9 10 |
# File 'lib/archaeo/progress_report.rb', line 8 def downloaded_bytes @downloaded_bytes end |
#elapsed ⇒ Object
Returns the value of attribute elapsed
8 9 10 |
# File 'lib/archaeo/progress_report.rb', line 8 def elapsed @elapsed end |
#total ⇒ Object
Returns the value of attribute total
8 9 10 |
# File 'lib/archaeo/progress_report.rb', line 8 def total @total end |
Instance Method Details
#as_json ⇒ Object
46 47 48 |
# File 'lib/archaeo/progress_report.rb', line 46 def as_json(*) to_h.transform_values { |v| v.is_a?(Float) ? v.round(2) : v } end |
#eta ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/archaeo/progress_report.rb', line 24 def eta return nil if elapsed.nil? || elapsed.zero? return nil if total.nil? || current.nil? || current.zero? rate = current.to_f / elapsed remaining = total - current remaining / rate end |
#percent_complete ⇒ Object
12 13 14 15 16 |
# File 'lib/archaeo/progress_report.rb', line 12 def percent_complete return 0.0 if total.nil? || total.zero? (current.to_f / total * 100).round(1) end |
#speed ⇒ Object
18 19 20 21 22 |
# File 'lib/archaeo/progress_report.rb', line 18 def speed return 0.0 if elapsed.nil? || elapsed.zero? downloaded_bytes.to_f / elapsed end |
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/archaeo/progress_report.rb', line 33 def to_h { current: current, total: total, percent_complete: percent_complete, downloaded_bytes: downloaded_bytes, speed: speed, eta: eta, current_url: current_url, elapsed: elapsed, } end |