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', 'files']
ADV_ATTRIBUTES =
['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
15
# File 'lib/transmission-client/torrent.rb', line 12

def initialize(attributes)
  @attributes = attributes
  @adv_attributes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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 "Can't access that yet."
  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)


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

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

#downloading?Boolean

Returns:

  • (Boolean)


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

def downloading?
  self.status == DOWNLOAD
end

#idObject



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

def id
  @attributes['id']
end

#reannounceObject



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

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

#remove(delete_data = false) ⇒ Object



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

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

#seeding?Boolean

Returns:

  • (Boolean)


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

def seeding?
  self.status == SEED
end

#startObject



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

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

#stopObject



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

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

#stopped?Boolean

Returns:

  • (Boolean)


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

def stopped?
  self.status == STOPPED
end

#verifyObject



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

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