Class: Retort::Torrent

Inherits:
Rtorrent show all
Defined in:
lib/retort/torrent.rb

Constant Summary

Constants inherited from Rtorrent

Rtorrent::TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rtorrent

attribute, setup

Constructor Details

#initialize(attributes) ⇒ Torrent

Returns a new instance of Torrent.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/retort/torrent.rb', line 54

def initialize(attributes)

  attributes.each do |attrib, value|
    variable = "@#{attrib}".to_sym
    self.instance_variable_set variable, value
    if attrib =~ /is_/
      bool_value = value.truth
      variable = "@#{attrib.to_s.gsub(/is_/, "")}".to_sym
      self.instance_variable_set variable, bool_value
    end
  end

end

Class Method Details

.action(name, info_hash) ⇒ Object



47
48
49
# File 'lib/retort/torrent.rb', line 47

def action(name, info_hash)
  Service.call "d.#{name}", info_hash
end

.all(view = "main") ⇒ Object



31
32
33
34
35
36
37
# File 'lib/retort/torrent.rb', line 31

def all(view="main")
  methods = attributes.map {|key,value| "#{value}="}
  Service.call("d.multicall", view, *methods).map do |r|
    attributes = Hash[self.attributes.keys.zip(r)]
    Torrent.new attributes
  end
end

.load(url) ⇒ Object



43
44
45
# File 'lib/retort/torrent.rb', line 43

def load(url)
  Service.call "load_start", url
end

.viewsObject



39
40
41
# File 'lib/retort/torrent.rb', line 39

def views
  Service.call "view.list"
end

Instance Method Details

#actionsObject



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

def actions
  actions = []

  actions << (@state.truth ? :stop : :start)
  #actions << :check_hash unless @hash_checking
  actions << (@open ? :close : :open)

  unless @complete.truth
    actions << (@active ? :pause : :resume)
  end

  actions << :erase

  actions
end

#commit_prioritiesObject



94
95
96
# File 'lib/retort/torrent.rb', line 94

def commit_priorities
  Service.call("d.update_priorities",self.info_hash)
end

#completed_ratioObject



68
69
70
# File 'lib/retort/torrent.rb', line 68

def completed_ratio
  self.completed_raw/(self.size_raw.to_f)
end

#filesObject



91
92
93
# File 'lib/retort/torrent.rb', line 91

def files
  File.all(self.info_hash)
end

#statusObject



72
73
74
# File 'lib/retort/torrent.rb', line 72

def status
  return "complete" if @complete.truth
end