Class: RTorrent::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/rtorrent_xmlrpc/torrent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTorrent

Returns a new instance of Torrent.



10
11
12
13
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 10

def initialize
  @labels = []
  @files= []
end

Instance Attribute Details

#base_filenameObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def base_filename
  @base_filename
end

#base_pathObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def base_path
  @base_path
end

#completedObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def completed
  @completed
end

#down_totalObject

Returns the value of attribute down_total.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def down_total
  @down_total
end

#filesObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def files
  @files
end

#hashObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def hash
  @hash
end

#is_multi_fileObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def is_multi_file
  @is_multi_file
end

#labelsObject

Returns the value of attribute labels.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def labels
  @labels
end

#nameObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def name
  @name
end

#priorityObject

Returns the value of attribute priority.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def priority
  @priority
end

#ratioObject

Returns the value of attribute ratio.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def ratio
  @ratio
end

#sizeObject

Returns the value of attribute size.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def size
  @size
end

#tied_to_fileObject

Attributes



16
17
18
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16

def tied_to_file
  @tied_to_file
end

#up_totalObject

Returns the value of attribute up_total.



17
18
19
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17

def up_total
  @up_total
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 19

def completed?
  self.completed
end

#has_label?(label) ⇒ Boolean

Test if torrent has a specific label

Returns:

  • (Boolean)


120
121
122
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 120

def has_label?(label)
  @labels.include? label.to_s
end

#labels_strObject



32
33
34
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 32

def labels_str
  @labels.join(', ')
end

#pp(with_files = false) ⇒ Object

All torrent data dumped to screen in color



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 100

def pp(with_files = false)
  puts "-------------- ".red
  puts "         hash: ".blue + self.hash.green
  puts "         name: ".blue + self.name.green
  puts "         size: ".blue + self.size.pretty.green
  puts "   downloaded: ".blue + self.down_total.pretty.green
  puts "     uploaded: ".blue + self.up_total.pretty.green
  puts "        ratio: ".blue + self.ratio.to_s.green
  puts "     priority: ".blue + self.priority_str.green
  puts "       labels: ".blue + self.labels_str.green
  puts "    completed: ".blue + self.completed.to_s.green
  if with_files
    puts "        files: ".blue
    @files.each { |file| puts "               " + file.green }
  end
end

#priority_strObject

Return priority converted to a human readable string



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 45

def priority_str
  case @priority
  when 0
    "Off"
  when 1
    "Low"
  when 2
    "Normal"
  when 3
    "High"
  else
    "Unknown"
  end
end

#to_hObject

Return hash of all values in Torrent



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 77

def to_h
  {
    base_filename: @base_filename,
    base_path: @base_path,
    completed: @completed,
    files: @files,
    hash: @hash,
    is_multi_file: @is_multi_file,
    labels: @labels,
    name: @name,
    priority: @priority,
    ratio: @ratio,
    size: @size,
    tied_to_file: @tied_to_file,
  }
end

#to_sObject

Convert object to string as json



95
96
97
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 95

def to_s
  self.to_h.to_json
end