Class: Nyaa::Downloader
- Inherits:
-
Object
- Object
- Nyaa::Downloader
- Defined in:
- lib/nyaa/downloader.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#response ⇒ Object
Returns the value of attribute response.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #failed? ⇒ Boolean
-
#initialize(url, path, retries = 3) ⇒ Downloader
constructor
A new instance of Downloader.
- #save ⇒ Object
Constructor Details
#initialize(url, path, retries = 3) ⇒ Downloader
Returns a new instance of Downloader.
7 8 9 10 11 12 13 14 15 |
# File 'lib/nyaa/downloader.rb', line 7 def initialize(url, path, retries = 3) self.target = url self.destination = Nyaa::Utils.safe_path(path) self.retries = retries self.response = request self.filename = name_from_disposition @fail = nil end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
4 5 6 |
# File 'lib/nyaa/downloader.rb', line 4 def destination @destination end |
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/nyaa/downloader.rb', line 5 def filename @filename end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/nyaa/downloader.rb', line 5 def response @response end |
#retries ⇒ Object
Returns the value of attribute retries.
4 5 6 |
# File 'lib/nyaa/downloader.rb', line 4 def retries @retries end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'lib/nyaa/downloader.rb', line 4 def target @target end |
Instance Method Details
#failed? ⇒ Boolean
28 29 30 |
# File 'lib/nyaa/downloader.rb', line 28 def failed? @fail end |
#save ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/nyaa/downloader.rb', line 17 def save unless @fail path = self.destination + '/' + filename; File.open("#{self.destination}/#{filename}", 'w') do |f| f.write(self.response.read) end return path; end return nil; end |