Class: PDTP::Server::BandwidthEstimator::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdtp/server/bandwidth_estimator.rb

Overview

Inner class for storing a transfer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time, bytes_transferred) ⇒ Transfer

Returns a new instance of Transfer.

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
# File 'lib/pdtp/server/bandwidth_estimator.rb', line 37

def initialize(start_time, end_time, bytes_transferred)
  # Avoid division by zero or negative transfer rates
  raise ArgumentError, "end_time must exceed start_time" unless end_time > start_time
  
  @start_time, @end_time = start_time, end_time
  
  # Calculate transfer rate in bytes per second
  @rate = (bytes_transferred / (end_time - start_time)).to_i
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



35
36
37
# File 'lib/pdtp/server/bandwidth_estimator.rb', line 35

def end_time
  @end_time
end

#rateObject (readonly)

Returns the value of attribute rate.



35
36
37
# File 'lib/pdtp/server/bandwidth_estimator.rb', line 35

def rate
  @rate
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



35
36
37
# File 'lib/pdtp/server/bandwidth_estimator.rb', line 35

def start_time
  @start_time
end