class Transmission::Model::Torrent

Attributes

attributes[RW]
connector[RW]
deleted[RW]
ids[RW]
torrents[RW]

Public Class Methods

add(options = {}) click to toggle source
# File lib/transmission/model/torrent.rb, line 127
def add(options = {})
  rpc = options[:connector] || connector
  body = rpc.add_torrent options[:arguments]
  raise DuplicateTorrentError if body['torrent-duplicate']
  find body['torrent-added']['id'], options
end
all(options = {}) click to toggle source
# File lib/transmission/model/torrent.rb, line 113
def all(options = {})
  rpc = options[:connector] || connector
  body = rpc.get_torrent nil, options[:fields]
  Torrent.new body['torrents'], rpc
end
connector() click to toggle source
# File lib/transmission/model/torrent.rb, line 144
def connector
  Transmission::Config.get_connector
end
find(id, options = {}) click to toggle source
# File lib/transmission/model/torrent.rb, line 119
def find(id, options = {})
  rpc = options[:connector] || connector
  ids = id.is_a?(Array) ? id : [id]
  body = rpc.get_torrent ids, options[:fields]
  raise TorrentNotFoundError if body['torrents'].size == 0
  Torrent.new body['torrents'], rpc
end
new(torrent_object, connector) click to toggle source
# File lib/transmission/model/torrent.rb, line 11
def initialize(torrent_object, connector)
  if torrent_object.is_a? Array
    is_single = torrent_object.size == 1
    @attributes = is_single ? torrent_object.first : {}
    @ids = is_single ? [@attributes['id'].to_i] : []
    @torrents = torrent_object.inject([]) do |torrents, torrent|
      @ids << torrent['id'].to_i
      torrents << Torrent.new([torrent], connector)
    end unless is_single
  end
  @connector = connector
end
start_all!(options = {}) click to toggle source
# File lib/transmission/model/torrent.rb, line 134
def start_all!(options = {})
  rpc = options[:connector] || connector
  rpc.start_torrent nil
end
stop_all!(options = {}) click to toggle source
# File lib/transmission/model/torrent.rb, line 139
def stop_all!(options = {})
  rpc = options[:connector] || connector
  rpc.stop_torrent nil
end

Public Instance Methods

delete!(remove_local_data = false) click to toggle source
# File lib/transmission/model/torrent.rb, line 24
def delete!(remove_local_data = false)
  connector.remove_torrent @ids, remove_local_data
  @deleted = true
end
finished?() click to toggle source
# File lib/transmission/model/torrent.rb, line 78
def finished?
  self.percent_done == 1
end
is_multi?() click to toggle source
# File lib/transmission/model/torrent.rb, line 74
def is_multi?
  @ids.size > 1
end
method_missing(symbol, *args) click to toggle source
Calls superclass method
# File lib/transmission/model/torrent.rb, line 99
def method_missing(symbol, *args)
  string = symbol.to_s
  if string[-1] == '='
    string = string[0..-2]
    key = Transmission::Arguments::TorrentSet.real_key string
    return @attributes[key] = args.first if !!key
  else
    key = Transmission::Fields::TorrentGet.real_key string
    return @attributes[key] if !!key
  end
  super
end
move_bottom!() click to toggle source
# File lib/transmission/model/torrent.rb, line 46
def move_bottom!
  connector.move_bottom_torrent @ids
end
move_down!() click to toggle source
# File lib/transmission/model/torrent.rb, line 38
def move_down!
  connector.move_down_torrent @ids
end
move_top!() click to toggle source
# File lib/transmission/model/torrent.rb, line 42
def move_top!
  connector.move_top_torrent @ids
end
move_up!() click to toggle source
# File lib/transmission/model/torrent.rb, line 34
def move_up!
  connector.move_up_torrent @ids
end
re_announce!() click to toggle source
# File lib/transmission/model/torrent.rb, line 66
def re_announce!
  connector.re_announce_torrent @ids
end
reload!() click to toggle source
# File lib/transmission/model/torrent.rb, line 82
def reload!
  torrents = Torrent.find @ids, connector: @connector
  @ids = torrents.ids
  @attributes = torrents.attributes
  @torrents = torrents.torrents
end
save!() click to toggle source
# File lib/transmission/model/torrent.rb, line 29
def save!
  filtered = Transmission::Arguments::TorrentSet.filter @attributes
  connector.set_torrent @ids, filtered
end
set_location(new_location, move = false) click to toggle source
# File lib/transmission/model/torrent.rb, line 70
def set_location(new_location, move = false)
  connector.torrent_set_location @ids,  location: new_location, move: move
end
start!() click to toggle source
# File lib/transmission/model/torrent.rb, line 50
def start!
  connector.start_torrent @ids
end
start_now!() click to toggle source
# File lib/transmission/model/torrent.rb, line 54
def start_now!
  connector.start_torrent_now @ids
end
stop!() click to toggle source
# File lib/transmission/model/torrent.rb, line 58
def stop!
  connector.stop_torrent @ids
end
to_json() click to toggle source
# File lib/transmission/model/torrent.rb, line 89
def to_json
  if is_multi?
    @torrents.inject([]) do |torrents, torrent|
      torrents << torrent.to_json
    end
  else
    @attributes
  end
end
verify!() click to toggle source
# File lib/transmission/model/torrent.rb, line 62
def verify!
  connector.verify_torrent @ids
end