Class: TorrentRSS::Torrent
- Inherits:
-
Object
- Object
- TorrentRSS::Torrent
- Defined in:
- lib/torrent_rss/torrent.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #download(directory) ⇒ Object
-
#initialize ⇒ Torrent
constructor
A new instance of Torrent.
Constructor Details
#initialize ⇒ Torrent
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
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/torrent_rss/torrent.rb', line 4 def id @id end |
#summary ⇒ Object
Returns the value of attribute summary.
4 5 6 |
# File 'lib/torrent_rss/torrent.rb', line 4 def summary @summary end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/torrent_rss/torrent.rb', line 4 def title @title end |
#url ⇒ Object
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 |