Class: Crankshaft::Torrent
- Inherits:
-
Object
- Object
- Crankshaft::Torrent
show all
- Defined in:
- lib/crankshaft/torrent.rb
Constant Summary
collapse
- ATTRS =
Default attributes fetched with each torrent
[
:addedDate, :comment, :creator, :dateCreated, :files, :hashString, :id, :isPrivate,
:magnetLink, :name, :pieceCount, :pieceSize, :startDate, :trackers, :totalSize
]
Instance Method Summary
collapse
Constructor Details
#initialize(session, attrs = {}) ⇒ Torrent
Returns a new instance of Torrent.
12
13
14
15
16
17
|
# File 'lib/crankshaft/torrent.rb', line 12
def initialize(session, attrs = {})
@session = session
@attrs = attrs.keys.inject({}) do |hash, key|
hash.tap {|h| h[key.to_sym] = attrs[key] }
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
63
64
65
|
# File 'lib/crankshaft/torrent.rb', line 63
def method_missing(method, *args)
self[method]
end
|
Instance Method Details
#[](attribute) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/crankshaft/torrent.rb', line 51
def [](attribute)
attribute = attribute.to_sym
return @attrs[attribute] if @attrs.include?(attribute)
arguments = { :ids => [ self['id'] ], :fields => [ attribute ] }
response = @session.execute('torrent-get', arguments)
if response['result'] == 'success'
attrs = response['arguments']['torrents'][0]
return attrs[attribute.to_s]
end
end
|
#files ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/crankshaft/torrent.rb', line 70
def files
@files ||= begin
self['files'].map do |file|
Crankshaft::File.new(self, file)
end
end
end
|
#reannounce ⇒ Object
37
38
39
40
|
# File 'lib/crankshaft/torrent.rb', line 37
def reannounce
arguments = { :ids => [ self['id'] ] }
@session.execute('torrent-reannounce')
end
|
#remove(delete = false) ⇒ Object
42
43
44
45
|
# File 'lib/crankshaft/torrent.rb', line 42
def remove(delete = false)
arguments = { :ids => [ self['id'] ], 'delete-local-data' => delete }
@session.execute('torrent-remove', arguments)
end
|
#start ⇒ Object
22
23
24
25
|
# File 'lib/crankshaft/torrent.rb', line 22
def start
arguments = { :ids => [ self['id'] ] }
@session.execute('torrent-start', arguments)
end
|
#stop ⇒ Object
27
28
29
30
|
# File 'lib/crankshaft/torrent.rb', line 27
def stop
arguments = { :ids => [ self['id'] ] }
@session.execute('torrent-stop', arguments)
end
|
#verify ⇒ Object
32
33
34
35
|
# File 'lib/crankshaft/torrent.rb', line 32
def verify
arguments = { :ids => [ self['id'] ] }
@session.execute('torrent-verify', arguments)
end
|