Class: TorrentRSS::Torrent

Inherits:
Object
  • Object
show all
Defined in:
lib/torrent_rss/torrent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTorrent

Returns a new instance of Torrent.



15
16
17
18
19
# File 'lib/torrent_rss/torrent.rb', line 15

def initialize
  @connection = Faraday.new do |builder|
    builder.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/torrent_rss/torrent.rb', line 4

def id
  @id
end

#summaryObject

Returns the value of attribute summary.



4
5
6
# File 'lib/torrent_rss/torrent.rb', line 4

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/torrent_rss/torrent.rb', line 4

def title
  @title
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/torrent_rss/torrent.rb', line 4

def url
  @url
end

Class Method Details

.from_entry(entry) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/torrent_rss/torrent.rb', line 5

def self.from_entry entry
  torrent = new      

  [:id, :url, :title, :summary].each do |attr|
    torrent.send "#{attr}=", entry.send("#{attr}")
  end

  torrent
end

Instance Method Details

#download(directory) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/torrent_rss/torrent.rb', line 21

def download directory
  response = @connection.get @url
  if response.success?
    filename = response.headers['content-disposition'].match(/filename=\"(.+)\"/)[1]
    File.write "#{directory}/#{filename}", response.body
  end
  response.success?
end