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.
12 13 14 15 16 17 18 19 20 |
# File 'lib/kat_search/link.rb', line 12 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.
10 11 12 |
# File 'lib/kat_search/link.rb', line 10 def download_url @download_url end |
#leechers ⇒ Object (readonly)
Returns the value of attribute leechers.
10 11 12 |
# File 'lib/kat_search/link.rb', line 10 def leechers @leechers end |
#seeders ⇒ Object (readonly)
Returns the value of attribute seeders.
10 11 12 |
# File 'lib/kat_search/link.rb', line 10 def seeders @seeders end |
Instance Method Details
#download(path = './') ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kat_search/link.rb', line 38 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
26 27 28 |
# File 'lib/kat_search/link.rb', line 26 def filename @filename ||= "#{CGI.unescape(@params['name'])}.#{@params['extension']}" end |
#info_hash ⇒ Object
34 35 36 |
# File 'lib/kat_search/link.rb', line 34 def info_hash @info_hash ||= extract_hash end |
#magnet ⇒ Object
30 31 32 |
# File 'lib/kat_search/link.rb', line 30 def magnet @magnet ||= @params['magnet'] end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/kat_search/link.rb', line 22 def to_s "#{filename.ljust(@@max_length_name + 2)} (#{@seeders.green}/#{@leechers.red})" end |