Class: Pirata::Torrent
- Inherits:
-
Object
- Object
- Pirata::Torrent
- Defined in:
- lib/pirata/torrent.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#magnet ⇒ Object
readonly
Returns the value of attribute magnet.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.find_by_id(id) ⇒ Object
Return a Torrent object from a corresponding ID.
- .parse_html(url) ⇒ Object
Instance Method Summary collapse
-
#initialize(params_hash) ⇒ Torrent
constructor
A new instance of Torrent.
- #update_params! ⇒ Object
Constructor Details
#initialize(params_hash) ⇒ Torrent
Returns a new instance of Torrent.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pirata/torrent.rb', line 11 def initialize(params_hash) @params = params_hash @title = @params[:title] @category = @params[:category] @url = @params[:url] @id = @params[:id] @magnet = @params[:magnet] build_getters() end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
9 10 11 |
# File 'lib/pirata/torrent.rb', line 9 def category @category end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/pirata/torrent.rb', line 9 def id @id end |
#magnet ⇒ Object (readonly)
Returns the value of attribute magnet.
9 10 11 |
# File 'lib/pirata/torrent.rb', line 9 def magnet @magnet end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/pirata/torrent.rb', line 9 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/pirata/torrent.rb', line 9 def url @url end |
Class Method Details
.find_by_id(id) ⇒ Object
Return a Torrent object from a corresponding ID
23 24 25 26 27 28 29 30 31 |
# File 'lib/pirata/torrent.rb', line 23 def self.find_by_id(id) raise "Invalid torrent ID format. Must be an integer" if id.class != Fixnum url = Pirata.config[:base_url] + "/torrent" + "/#{URI.escape(id.to_s)}" html = self.parse_html(url) results_hash = parse_torrent_page(html) Pirata::Torrent.new(results_hash) end |
.parse_html(url) ⇒ Object
44 45 46 47 |
# File 'lib/pirata/torrent.rb', line 44 def parse_html(url) response = open(url,'User-Agent' => 'ruby') Nokogiri::HTML(response) end |
Instance Method Details
#update_params! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/pirata/torrent.rb', line 33 def update_params! html = Pirata::Torrent.parse_html(url) updated_params = Pirata::Torrent.parse_torrent_page(html) @params.merge!(updated_params) end |