Class: RTorrent::Torrent
- Inherits:
-
Object
- Object
- RTorrent::Torrent
- Defined in:
- lib/rtorrent_xmlrpc/torrent.rb
Instance Attribute Summary collapse
-
#base_filename ⇒ Object
Attributes.
-
#base_path ⇒ Object
Attributes.
-
#completed ⇒ Object
Attributes.
-
#down_total ⇒ Object
Returns the value of attribute down_total.
-
#files ⇒ Object
Attributes.
-
#hash ⇒ Object
Attributes.
-
#is_multi_file ⇒ Object
Attributes.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#name ⇒ Object
Attributes.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#ratio ⇒ Object
Returns the value of attribute ratio.
-
#size ⇒ Object
Returns the value of attribute size.
-
#tied_to_file ⇒ Object
Attributes.
-
#up_total ⇒ Object
Returns the value of attribute up_total.
Instance Method Summary collapse
- #completed? ⇒ Boolean
-
#has_label?(label) ⇒ Boolean
Test if torrent has a specific label.
-
#initialize ⇒ Torrent
constructor
A new instance of Torrent.
- #labels_str ⇒ Object
-
#pp(with_files = false) ⇒ Object
All torrent data dumped to screen in color.
-
#priority_str ⇒ Object
Return priority converted to a human readable string.
-
#to_h ⇒ Object
Return hash of all values in Torrent.
-
#to_s ⇒ Object
Convert object to string as json.
Constructor Details
#initialize ⇒ Torrent
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_filename ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def base_filename @base_filename end |
#base_path ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def base_path @base_path end |
#completed ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def completed @completed end |
#down_total ⇒ Object
Returns the value of attribute down_total.
17 18 19 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17 def down_total @down_total end |
#files ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def files @files end |
#hash ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def hash @hash end |
#is_multi_file ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def is_multi_file @is_multi_file end |
#labels ⇒ Object
Returns the value of attribute labels.
17 18 19 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17 def labels @labels end |
#name ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def name @name end |
#priority ⇒ Object
Returns the value of attribute priority.
17 18 19 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17 def priority @priority end |
#ratio ⇒ Object
Returns the value of attribute ratio.
17 18 19 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17 def ratio @ratio end |
#size ⇒ Object
Returns the value of attribute size.
17 18 19 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 17 def size @size end |
#tied_to_file ⇒ Object
Attributes
16 17 18 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 16 def tied_to_file @tied_to_file end |
#up_total ⇒ Object
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
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
120 121 122 |
# File 'lib/rtorrent_xmlrpc/torrent.rb', line 120 def has_label?(label) @labels.include? label.to_s end |
#labels_str ⇒ Object
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_str ⇒ Object
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_h ⇒ Object
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_s ⇒ Object
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 |