Class: Transmission::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/transmission-client/torrent.rb

Constant Summary collapse

ATTRIBUTES =
['activityDate', 'addedDate', 'bandwidthPriority', 'comment', 'corruptEver', 'creator', 'dateCreated', 'desiredAvailable', 'doneDate', 'downloadDir', 'downloadedEver', 'downloadLimit', 'downloadLimited', 'error', 'errorString', 'eta', 'hashString', 'haveUnchecked', 'haveValid', 'honorsSessionLimits', 'id', 'isPrivate', 'leftUntilDone', 'manualAnnounceTime', 'maxConnectedPeers', 'name', 'peer-limit', 'peersConnected', 'peersGettingFromUs', 'peersKnown', 'peersSendingToUs', 'percentDone', 'pieces', 'pieceCount', 'pieceSize', 'rateDownload', 'rateUpload', 'recheckProgress', 'seedRatioLimit', 'seedRatioMode', 'sizeWhenDone', 'startDate', 'status', 'swarmSpeed', 'totalSize', 'torrentFile', 'uploadedEver', 'uploadLimit', 'uploadLimited', 'uploadRatio', 'webseedsSendingToUs']
ADV_ATTRIBUTES =
['files', 'fileStats', 'peers', 'peersFrom', 'priorities', 'trackers', 'trackerStats', 'wanted', 'webseeds']
SETABLE_ATTRIBUTES =
['bandwidthPriority', 'downloadLimit', 'downloadLimited', 'files-wanted', 'files-unwanted', 'honorsSessionLimits', 'ids', 'location', 'peer-limit', 'priority-high', 'priority-low', 'priority-normal', 'seedRatioLimit', 'seedRatioMode', 'uploadLimit', 'uploadLimited']
CHECK_WAIT =
1
CHECK =
2
DOWNLOAD =
4
SEED =
8
STOPPED =
16

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Torrent

Returns a new instance of Torrent.



12
13
14
# File 'lib/transmission-client/torrent.rb', line 12

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/transmission-client/torrent.rb', line 56

def method_missing(m, *args, &block)
  if ATTRIBUTES.include? m.to_s
    return @attributes[m.to_s]
  elsif ADV_ATTRIBUTES.include? m.to_s
    raise "Attribute not yet supported."
  elsif m[-1..-1] == '='
    if SETABLE_ATTRIBUTES.include? m[0..-2]
      Connection.send('torrent-set', {'ids' => [@attributes['id']], m[0..-2] => args.first})  
    else
      raise "Invalid Attribute."
    end
  else
    raise "Invalid Attribute."
  end
end

Instance Method Details

#checking?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/transmission-client/torrent.rb', line 44

def checking?
  self.status == CHECK || self.status == CHECK_WAIT
end

#downloading?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/transmission-client/torrent.rb', line 36

def downloading?
  self.status == DOWNLOAD
end

#idObject



52
53
54
# File 'lib/transmission-client/torrent.rb', line 52

def id
  @attributes['id']
end

#reannounceObject



28
29
30
# File 'lib/transmission-client/torrent.rb', line 28

def reannounce
  Connection.send('torrent-reannounce', {'ids' => @attributes['id']})
end

#remove(delete_data = false) ⇒ Object



32
33
34
# File 'lib/transmission-client/torrent.rb', line 32

def remove(delete_data = false)
  Connection.send('torrent-remove', {'ids' => @attributes['id'], 'delete-local-data' => delete_data })
end

#seeding?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/transmission-client/torrent.rb', line 48

def seeding?
  self.status == SEED
end

#startObject



16
17
18
# File 'lib/transmission-client/torrent.rb', line 16

def start
  Connection.send('torrent-start', {'ids' => @attributes['id']})
end

#stopObject



20
21
22
# File 'lib/transmission-client/torrent.rb', line 20

def stop
  Connection.send('torrent-stop', {'ids' => @attributes['id']})
end

#stopped?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/transmission-client/torrent.rb', line 40

def stopped?
  self.status == STOPPED
end

#verifyObject



24
25
26
# File 'lib/transmission-client/torrent.rb', line 24

def verify
  Connection.send('torrent-verify', {'ids' => @attributes['id']})
end