Class: Retort::File
Overview
A file inside a torrent
Constant Summary collapse
- PRIORITY_HIGH =
2
- PRIORITY_NORMAL =
1
Constants inherited from Rtorrent
Class Method Summary collapse
Instance Method Summary collapse
- #[](v) ⇒ Object
- #completed? ⇒ Boolean
-
#initialize(attributes, meta) ⇒ File
constructor
A new instance of File.
- #set_priority(prio, commit = true) ⇒ Object
Methods inherited from Rtorrent
Constructor Details
#initialize(attributes, meta) ⇒ File
Returns a new instance of File.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/retort/file.rb', line 25 def initialize(attributes, ) @index = .fetch(:index) @torrent_info_hash = .fetch(:torrent_info_hash) @attributes = {} attributes.each do |attrib, value| variable = "@#{attrib}".to_sym if attrib =~ /is_/ bool_value = value.truth variable = "@#{attrib.to_s.gsub(/is_/, "")}".to_sym self.instance_variable_set variable, bool_value elsif attrib =~ /get_/ variable = "@#{attrib.to_s.gsub(/get_/, "")}".to_sym self.instance_variable_set variable, value else self.instance_variable_set variable, value end end end |
Class Method Details
.all(info_hash) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/retort/file.rb', line 48 def self.all(info_hash) methods = attributes.map {|key,value| "#{value}="} Service.call("f.multicall", info_hash,"", *methods).map.with_index do |r, index| attributes = Hash[self.attributes.keys.zip(r)] self.new attributes, {torrent_info_hash: info_hash, index: index} end end |
Instance Method Details
#[](v) ⇒ Object
22 23 24 |
# File 'lib/retort/file.rb', line 22 def [](v) instance_variable_get "@#{v}".to_sym end |
#completed? ⇒ Boolean
44 45 46 |
# File 'lib/retort/file.rb', line 44 def completed? @completed_chunks == @size_chunks end |
#set_priority(prio, commit = true) ⇒ Object
59 60 61 62 |
# File 'lib/retort/file.rb', line 59 def set_priority(prio,commit=true) Service.call("f.set_priority",@torrent_info_hash,@index, prio) Torrent.new({info_hash: @torrent_info_hash}).commit_priorities if commit end |