Class: TorrentReactor::Search
- Inherits:
-
Object
- Object
- TorrentReactor::Search
- Defined in:
- lib/torrent_reactor/base.rb
Instance Attribute Summary collapse
-
#caching ⇒ Object
Returns the value of attribute caching.
-
#category_id ⇒ Object
Returns the value of attribute category_id.
-
#page ⇒ Object
Returns the value of attribute page.
-
#results ⇒ Object
Returns the value of attribute results.
-
#search_string ⇒ Object
Returns the value of attribute search_string.
Instance Method Summary collapse
- #cached_filename ⇒ Object
- #execute ⇒ Object
- #fetch_search_results ⇒ Object
- #get_search_results ⇒ Object
-
#initialize(search_string) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(search_string) ⇒ Search
Returns a new instance of Search.
5 6 7 8 9 10 11 |
# File 'lib/torrent_reactor/base.rb', line 5 def initialize(search_string) self.search_string = URI.encode(search_string) # self.category_id = TorrentReactor::Categories::IDS[category.upcase.strip.gsub(/S$/, "").to_sym] unless category == 0 self.page = -1 @results = TorrentReactor::ResultSet.new(self) end |
Instance Attribute Details
#caching ⇒ Object
Returns the value of attribute caching.
3 4 5 |
# File 'lib/torrent_reactor/base.rb', line 3 def caching @caching end |
#category_id ⇒ Object
Returns the value of attribute category_id.
3 4 5 |
# File 'lib/torrent_reactor/base.rb', line 3 def category_id @category_id end |
#page ⇒ Object
Returns the value of attribute page.
3 4 5 |
# File 'lib/torrent_reactor/base.rb', line 3 def page @page end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/torrent_reactor/base.rb', line 3 def results @results end |
#search_string ⇒ Object
Returns the value of attribute search_string.
3 4 5 |
# File 'lib/torrent_reactor/base.rb', line 3 def search_string @search_string end |
Instance Method Details
#cached_filename ⇒ Object
39 40 41 |
# File 'lib/torrent_reactor/base.rb', line 39 def cached_filename File.join("tmp", "searches", "#{search_string}_#{category_id}_#{page}.html") end |
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/torrent_reactor/base.rb', line 27 def execute return nil if search_string.nil? self.page += 1 if (@results.size < @results.total_results) doc = get_search_results end next_page(doc) end |
#fetch_search_results ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/torrent_reactor/base.rb', line 44 def fetch_search_results base_search_url = 'http://www.torrentreactor.net/search.php?search=&words=' sortstring = "&sid=&type=1&exclude=&orderby=a.seeds&cid=5&asc=0&x=47&y=6" searchurl = base_search_url << search_string.split.join("+") << sortstring Hpricot(URI.parse(searchurl).read) end |
#get_search_results ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/torrent_reactor/base.rb', line 13 def get_search_results if caching && File.exists?(cached_filename) content = File.read(cached_filename) else content = fetch_search_results FileUtils.mkdir_p("tmp/searches") File.open(cached_filename, "w") do |f| f.write(content) end end content end |