Class: Archaeo::ProgressReport

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current

Returns:

  • (Object)

    the current value of current



8
9
10
# File 'lib/archaeo/progress_report.rb', line 8

def current
  @current
end

#current_urlObject

Returns the value of attribute current_url

Returns:

  • (Object)

    the current value of current_url



8
9
10
# File 'lib/archaeo/progress_report.rb', line 8

def current_url
  @current_url
end

#downloaded_bytesObject

Returns the value of attribute downloaded_bytes

Returns:

  • (Object)

    the current value of downloaded_bytes



8
9
10
# File 'lib/archaeo/progress_report.rb', line 8

def downloaded_bytes
  @downloaded_bytes
end

#elapsedObject

Returns the value of attribute elapsed

Returns:

  • (Object)

    the current value of elapsed



8
9
10
# File 'lib/archaeo/progress_report.rb', line 8

def elapsed
  @elapsed
end

#totalObject

Returns the value of attribute total

Returns:

  • (Object)

    the current value of total



8
9
10
# File 'lib/archaeo/progress_report.rb', line 8

def total
  @total
end

Instance Method Details

#as_jsonObject



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

#etaObject



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_completeObject



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

#speedObject



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_hObject



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