Class: TorrentApi
- Inherits:
-
Object
- Object
- TorrentApi
- Defined in:
- lib/torrent_api.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
-
#search_term ⇒ Object
Returns the value of attribute search_term.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service = :pirate_bay, search_term = nil) ⇒ TorrentApi
constructor
A new instance of TorrentApi.
- #search ⇒ Object
Constructor Details
#initialize(service = :pirate_bay, search_term = nil) ⇒ TorrentApi
Returns a new instance of TorrentApi.
25 26 27 28 29 30 |
# File 'lib/torrent_api.rb', line 25 def initialize(service=:pirate_bay, search_term=nil) @service = service @search_term = search_term @results = search if @search_term end |
Instance Attribute Details
#results ⇒ Object
Returns the value of attribute results.
23 24 25 |
# File 'lib/torrent_api.rb', line 23 def results @results end |
#search_term ⇒ Object
Returns the value of attribute search_term.
23 24 25 |
# File 'lib/torrent_api.rb', line 23 def search_term @search_term end |
#service ⇒ Object
Returns the value of attribute service.
23 24 25 |
# File 'lib/torrent_api.rb', line 23 def service @service end |
Instance Method Details
#search ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/torrent_api.rb', line 32 def search if @service == :all results = [] results << PirateBay::Search.new(@search_term).execute results << Demonoid::Search.new(@search_term).execute results << TorrentReactor::Search.new(@search_term).execute results = results.flatten.sort_by { |sort| -(sort.seeds) } else case @service when :pirate_bay # do something handler = PirateBay::Search.new(@search_term) when :demonoid # do something handler = Demonoid::Search.new(@search_term) when :torrent_reactor # do something else handler = TorrentReactor::Search.new(@search_term) else raise "You must select a valid service provider" end results = handler.execute end @results = results end |