Class: Trans::Api::File
- Inherits:
-
Object
- Object
- Trans::Api::File
- Defined in:
- lib/trans-api/file.rb
Instance Method Summary collapse
- #bytes_completed ⇒ Object
- #bytes_total ⇒ Object
- #id ⇒ Object
-
#initialize(options = {}) ⇒ File
constructor
A new instance of File.
- #name ⇒ Object
- #priority ⇒ Object
- #stat ⇒ Object
- #unwant ⇒ Object
- #want ⇒ Object
- #wanted? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/trans-api/file.rb', line 8 def initialize(={}) @torrent = .delete :torrent @torrent_fields = .delete :fields @fields = [:file] # set default stats @torrent_fields[:files_unwanted] ||= [] @torrent_fields[:files_wanted] ||= [] # if @fields[:fileStat][:wanted] == false # @torrent_fields[:files_unwanted] << self.id # else # @torrent_fields[:files_wanted] << self.id # end @client = Client.new end |
Instance Method Details
#bytes_completed ⇒ Object
37 38 39 |
# File 'lib/trans-api/file.rb', line 37 def bytes_completed @fields[:bytesCompleted] end |
#bytes_total ⇒ Object
41 42 43 |
# File 'lib/trans-api/file.rb', line 41 def bytes_total @fields[:length] end |
#id ⇒ Object
25 26 27 |
# File 'lib/trans-api/file.rb', line 25 def id @fields[:id] end |
#name ⇒ Object
29 30 31 |
# File 'lib/trans-api/file.rb', line 29 def name @fields[:name] end |
#priority ⇒ Object
45 46 47 |
# File 'lib/trans-api/file.rb', line 45 def priority @fields[:fileStat][:priority] end |
#stat ⇒ Object
33 34 35 |
# File 'lib/trans-api/file.rb', line 33 def stat @fields[:fileStat] end |
#unwant ⇒ Object
49 50 51 52 53 |
# File 'lib/trans-api/file.rb', line 49 def unwant @torrent_fields[:files_wanted].delete self.id if @torrent_fields[:files_wanted].include? self.id @torrent_fields[:files_unwanted] << self.id unless @torrent_fields[:files_unwanted].include? self.id @fields[:fileStat][:wanted] = false end |
#want ⇒ Object
55 56 57 58 59 |
# File 'lib/trans-api/file.rb', line 55 def want @torrent_fields[:files_wanted] << self.id unless @torrent_fields[:files_wanted].include? self.id @torrent_fields[:files_unwanted].delete self.id if @torrent_fields[:files_unwanted].include? self.id @fields[:fileStat][:wanted] = true end |
#wanted? ⇒ Boolean
61 62 63 |
# File 'lib/trans-api/file.rb', line 61 def wanted? @fields[:fileStat][:wanted] end |