Class: KatSearch::Link
- Inherits:
-
Object
- Object
- KatSearch::Link
- Defined in:
- lib/kat_search/link.rb
Overview
Object that contains the info for a torrent file
Instance Attribute Summary collapse
-
#download_url ⇒ Object
readonly
Returns the value of attribute download_url.
-
#leechers ⇒ Object
readonly
Returns the value of attribute leechers.
-
#seeders ⇒ Object
readonly
Returns the value of attribute seeders.
Instance Method Summary collapse
- #download(path = './') ⇒ Object
- #filename ⇒ Object
- #info_hash ⇒ Object
-
#initialize(params) ⇒ Link
constructor
A new instance of Link.
- #magnet ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params) ⇒ Link
Returns a new instance of Link.
13 14 15 16 17 18 19 20 21 |
# File 'lib/kat_search/link.rb', line 13 def initialize(params) @params = params @seeders = params['seeders'] @leechers = params['leechers'] @download_url = params['download_url'] # Get the longest filename for pretty print set_max_length_name(filename.length) end |
Instance Attribute Details
#download_url ⇒ Object (readonly)
Returns the value of attribute download_url.
11 12 13 |
# File 'lib/kat_search/link.rb', line 11 def download_url @download_url end |
#leechers ⇒ Object (readonly)
Returns the value of attribute leechers.
11 12 13 |
# File 'lib/kat_search/link.rb', line 11 def leechers @leechers end |
#seeders ⇒ Object (readonly)
Returns the value of attribute seeders.
11 12 13 |
# File 'lib/kat_search/link.rb', line 11 def seeders @seeders end |
Instance Method Details
#download(path = './') ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kat_search/link.rb', line 39 def download(path = './') response = HTTParty.get(@download_url) raise 'Wrong content-type. Aborting.' unless response.headers['content-type'].include? 'application/x-bittorrent' # Get file name from the url filename = @download_url[/\?title=(.+)/, 1] + '.torrent' open(File.join(path, filename), 'w') { |f| f << response } # return filename filename end |
#filename ⇒ Object
27 28 29 |
# File 'lib/kat_search/link.rb', line 27 def filename @filename ||= "#{CGI.unescape(@params['name'])}.#{@params['extension']}" end |
#info_hash ⇒ Object
35 36 37 |
# File 'lib/kat_search/link.rb', line 35 def info_hash @info_hash ||= extract_hash end |
#magnet ⇒ Object
31 32 33 |
# File 'lib/kat_search/link.rb', line 31 def magnet @magnet ||= @params['magnet'] end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/kat_search/link.rb', line 23 def to_s "#{filename.ljust(@@max_length_name + 2)} (#{@seeders.green}/#{@leechers.red})" end |