class RTorrent::Torrent

Constants

PRIORITIES
PRIORITY_HIGH
PRIORITY_LOW
PRIORITY_NORMAL
PRIORITY_OFF

Attributes

base_filename[RW]

Attributes

base_path[RW]

Attributes

completed[RW]

Attributes

down_total[RW]

Attributes

files[RW]

Attributes

hash[RW]

Attributes

is_multi_file[RW]

Attributes

labels[R]
name[RW]

Attributes

priority[R]
ratio[R]
size[RW]

Attributes

tied_to_file[RW]

Attributes

up_total[RW]

Attributes

Public Class Methods

new() click to toggle source
# File lib/rtorrent_xmlrpc/torrent.rb, line 16
def initialize
  @labels = []
  @files= []
end

Public Instance Methods

add_labels(labels) click to toggle source
# File lib/rtorrent_xmlrpc/torrent.rb, line 29
def add_labels(labels)
  labels = Array(labels)
  labels.map!(&:strip)
  self.labels = @labels | labels
end
completed?() click to toggle source
# File lib/rtorrent_xmlrpc/torrent.rb, line 25
def completed?
  self.completed
end
has_any_labels?(labels) click to toggle source

Test if torrent has any of the labels

# File lib/rtorrent_xmlrpc/torrent.rb, line 118
def has_any_labels?(labels)
  ! (@labels & labels).empty?
end
has_label?(label) click to toggle source

Test if torrent has a specific label

# File lib/rtorrent_xmlrpc/torrent.rb, line 113
def has_label?(label)
  @labels.include? label.to_s
end
labels_str() click to toggle source
# File lib/rtorrent_xmlrpc/torrent.rb, line 47
def labels_str
  @labels.join(', ')
end
pp(with_files = false) click to toggle source

All torrent data dumped to screen in color

# File lib/rtorrent_xmlrpc/torrent.rb, line 92
def pp(with_files = false)
  i = 12
  puts ("-" * i).red
  puts "%s %s" % ['hash:'.rjust(i).blue, self.hash.green]
  puts "%s %s" % ['name:'.rjust(i).blue, self.name.green]
  puts "%s %s" % ['size:'.rjust(i).blue, Filesize.new(self.size).pretty.green]
  puts "%s %s" % ['downloaded:'.rjust(i).blue, Filesize.new(self.down_total).pretty.green]
  puts "%s %s" % ['uploaded:'.rjust(i).blue, Filesize.new(self.up_total).pretty.green]
  puts "%s %s" % ['ratio:'.rjust(i).blue, self.ratio.to_s.green]
  puts "%s %s" % ['priority:'.rjust(i).blue, self.priority_str.green]
  puts "%s %s" % ['labels:'.rjust(i).blue, self.labels_str.green]
  puts "%s %s" % ['completed:'.rjust(i).blue, self.completed.to_s.green]
  if with_files
    puts "%s %s" % ['files:'.rjust(i).blue, @files.first.green]
    @files.each { |file| puts "%s %s" % [' ' * i, file.green] unless file == @files.first }
  end
end
priority_str() click to toggle source

Return priority converted to a human readable string

# File lib/rtorrent_xmlrpc/torrent.rb, line 60
def priority_str
  PRIORITIES[@priority]
end
remove_labels(labels) click to toggle source
# File lib/rtorrent_xmlrpc/torrent.rb, line 35
def remove_labels(labels)
  labels = Array(labels)
  labels.map!(&:strip)
  self.labels = @labels - labels
end
to_h() click to toggle source

Return hash of all values in Torrent

# File lib/rtorrent_xmlrpc/torrent.rb, line 69
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_s() click to toggle source

Convert object to string as json

# File lib/rtorrent_xmlrpc/torrent.rb, line 87
def to_s
  self.to_h.to_json
end