Class: UTorrent::File

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/u_torrent/file.rb

Constant Summary collapse

PRIORITIES =
{
  0 => "Don't Download",
  1 => 'Low Priority',
  2 => 'Normal Priority',
  3 => 'High Priority',
}
ATTRIBUTES =
[
  :name, :size, :downloaded, nil,
  nil, nil, nil, nil, nil, nil, nil, nil, nil
]

Instance Attribute Summary collapse

Attributes included from Base

#raw_array

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

included

Constructor Details

#initialize(array, index, torrent_id) ⇒ File

Returns a new instance of File.



23
24
25
26
27
# File 'lib/u_torrent/file.rb', line 23

def initialize(array, index, torrent_id)
  super(array)
  @index      = index
  @torrent_id = torrent_id
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



17
18
19
# File 'lib/u_torrent/file.rb', line 17

def index
  @index
end

#torrent_idObject (readonly)

Returns the value of attribute torrent_id.



17
18
19
# File 'lib/u_torrent/file.rb', line 17

def torrent_id
  @torrent_id
end

Class Method Details

.find_by_torrent_id_and_index(torrent_id, index) ⇒ Object



19
20
21
# File 'lib/u_torrent/file.rb', line 19

def self.find_by_torrent_id_and_index(torrent_id, index)
  UTorrent::Torrent.find(torrent_id).files[index]
end

Instance Method Details

#priorityObject



33
34
35
# File 'lib/u_torrent/file.rb', line 33

def priority
  @raw_array[3]
end

#priority=(priority) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/u_torrent/file.rb', line 41

def priority=(priority)
  UTorrent::Http.get_with_authentication(
    action: 'setprio',
    hash:    torrent_id,
    f:       index,
    p:       priority
  )
  refresh!
end

#priority_display_valueObject



29
30
31
# File 'lib/u_torrent/file.rb', line 29

def priority_display_value
  PRIORITIES[priority]
end

#refresh!Object



51
52
53
54
# File 'lib/u_torrent/file.rb', line 51

def refresh!
  file = self.class.find_by_torrent_id_and_index(torrent_id, index)
  @raw_array = file.raw_array
end

#skipObject



37
38
39
# File 'lib/u_torrent/file.rb', line 37

def skip
  send(:priority=, 0)
end