Class: QuartzTorrent::TorrentDataDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_flow/mock_client.rb,
lib/quartz_flow/wrappers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTorrentDataDelegate

Create a new TorrentDataDelegate. This is meant to only be called internally.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/quartz_flow/mock_client.rb', line 125

def initialize
  @info = nil
  @infoHash = nil
  @recommendedName = nil
  @downloadRate = nil
  @uploadRate = nil
  @downloadRateDataOnly = nil
  @uploadRateDataOnly = nil
  @completedBytes = nil
  @peers = nil
  @state = nil
  @completePieceBitfield = nil
  @metainfoLength = nil
  @metainfoCompletedLength = nil
  @paused = nil
end

Instance Attribute Details

#completedBytesObject

Returns the value of attribute completedBytes.



152
153
154
# File 'lib/quartz_flow/mock_client.rb', line 152

def completedBytes
  @completedBytes
end

#completePieceBitfieldObject

Returns the value of attribute completePieceBitfield.



157
158
159
# File 'lib/quartz_flow/mock_client.rb', line 157

def completePieceBitfield
  @completePieceBitfield
end

#downloadRateObject

Returns the value of attribute downloadRate.



148
149
150
# File 'lib/quartz_flow/mock_client.rb', line 148

def downloadRate
  @downloadRate
end

#downloadRateDataOnlyObject

Returns the value of attribute downloadRateDataOnly.



150
151
152
# File 'lib/quartz_flow/mock_client.rb', line 150

def downloadRateDataOnly
  @downloadRateDataOnly
end

#infoObject

Torrent Metainfo.info struct. This is nil if the torrent has no metadata and we haven’t downloaded it yet (i.e. a magnet link).



144
145
146
# File 'lib/quartz_flow/mock_client.rb', line 144

def info
  @info
end

#infoHashObject

Returns the value of attribute infoHash.



145
146
147
# File 'lib/quartz_flow/mock_client.rb', line 145

def infoHash
  @infoHash
end

#metainfoCompletedLengthObject

How much of the metainfo info we have downloaded in bytes. This is only set when the state is :downloading_metainfo



161
162
163
# File 'lib/quartz_flow/mock_client.rb', line 161

def metainfoCompletedLength
  @metainfoCompletedLength
end

#metainfoLengthObject

Length of metainfo info in bytes. This is only set when the state is :downloading_metainfo



159
160
161
# File 'lib/quartz_flow/mock_client.rb', line 159

def metainfoLength
  @metainfoLength
end

#pausedObject

Returns the value of attribute paused.



162
163
164
# File 'lib/quartz_flow/mock_client.rb', line 162

def paused
  @paused
end

#peersObject

Returns the value of attribute peers.



153
154
155
# File 'lib/quartz_flow/mock_client.rb', line 153

def peers
  @peers
end

#recommendedNameObject

Recommended display name for this torrent.



147
148
149
# File 'lib/quartz_flow/mock_client.rb', line 147

def recommendedName
  @recommendedName
end

#stateObject

State of the torrent. This may be one of :downloading_metainfo, :error, :checking_pieces, :running, :downloading_metainfo, or :deleted. The :deleted state indicates that the torrent that this TorrentDataDelegate refers to is no longer being managed by the peer client.



156
157
158
# File 'lib/quartz_flow/mock_client.rb', line 156

def state
  @state
end

#uploadRateObject

Returns the value of attribute uploadRate.



149
150
151
# File 'lib/quartz_flow/mock_client.rb', line 149

def uploadRate
  @uploadRate
end

#uploadRateDataOnlyObject

Returns the value of attribute uploadRateDataOnly.



151
152
153
# File 'lib/quartz_flow/mock_client.rb', line 151

def uploadRateDataOnly
  @uploadRateDataOnly
end

Instance Method Details

#to_hObject

Convert to a hash. Also flattens some of the data into new fields.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/quartz_flow/wrappers.rb', line 65

def to_h
  result = {}

  ## Extra fields added by this method:
  # Length of the torrent
  result[:dataLength] = @info ? @info.dataLength : 0
  # Percent complete
  pct = withCurrentAndTotalBytes{ |cur, total| (cur.to_f / total.to_f * 100.0).round 1 }
  result[:percentComplete] = pct
  # Time left
  secondsLeft = withCurrentAndTotalBytes do |cur, total|
    if @downloadRateDataOnly && @downloadRateDataOnly > 0
      (total.to_f - cur.to_f) / @downloadRateDataOnly 
    else
      0
    end
  end
  # Cap estimated time at 9999 hours
  secondsLeft = 35996400 if secondsLeft > 35996400
  result[:timeLeft] = Formatter.formatTime(secondsLeft)

  ## Regular fields
  result[:info] = @info ? @info.to_h : nil
  result[:infoHash] = @infoHash
  result[:recommendedName] = @recommendedName
  result[:downloadRate] = @downloadRate
  result[:uploadRate] = @uploadRate
  result[:downloadRateDataOnly] = @downloadRateDataOnly
  result[:uploadRateDataOnly] = @uploadRateDataOnly
  result[:completedBytes] = @completedBytes
  result[:peers] = @peers.collect{ |p| p.to_h }
  result[:state] = @state
  #result[:completePieceBitfield] = @completePieceBitfield
  result[:metainfoLength] = @metainfoLength
  result[:metainfoCompletedLength] = @metainfoCompletedLength
  result[:paused] = @paused
  result[:queued] = @queued
  result[:uploadRateLimit] = @uploadRateLimit
  result[:downloadRateLimit] = @downloadRateLimit
  result[:ratio] = @ratio
  result[:uploadDuration] = @uploadDuration
  result[:bytesUploaded] = @bytesUploaded
  result[:bytesDownloaded] = @bytesDownloaded
  result[:alarms] = @alarms.collect{ |a| a.to_h }

  result
end