Class: PDTP::Server::BandwidthEstimator::Transfer
- Inherits:
-
Object
- Object
- PDTP::Server::BandwidthEstimator::Transfer
- Defined in:
- lib/pdtp/server/bandwidth_estimator.rb
Overview
Inner class for storing a transfer
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#initialize(start_time, end_time, bytes_transferred) ⇒ Transfer
constructor
A new instance of Transfer.
Constructor Details
#initialize(start_time, end_time, bytes_transferred) ⇒ Transfer
Returns a new instance of Transfer.
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_time ⇒ Object (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 |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
35 36 37 |
# File 'lib/pdtp/server/bandwidth_estimator.rb', line 35 def rate @rate end |
#start_time ⇒ Object (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 |