Class: Demonoid::Search
- Inherits:
-
Object
- Object
- Demonoid::Search
- Defined in:
- lib/demonoid/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, category = 0) ⇒ Search
constructor
A new instance of Search.
Constructor Details
Instance Attribute Details
#caching ⇒ Object
Returns the value of attribute caching.
3 4 5 |
# File 'lib/demonoid/base.rb', line 3 def caching @caching end |
#category_id ⇒ Object
Returns the value of attribute category_id.
3 4 5 |
# File 'lib/demonoid/base.rb', line 3 def category_id @category_id end |
#page ⇒ Object
Returns the value of attribute page.
3 4 5 |
# File 'lib/demonoid/base.rb', line 3 def page @page end |
#results ⇒ Object
Returns the value of attribute results.
3 4 5 |
# File 'lib/demonoid/base.rb', line 3 def results @results end |
#search_string ⇒ Object
Returns the value of attribute search_string.
3 4 5 |
# File 'lib/demonoid/base.rb', line 3 def search_string @search_string end |
Instance Method Details
#cached_filename ⇒ Object
38 39 40 |
# File 'lib/demonoid/base.rb', line 38 def cached_filename File.join("tmp", "searches", "#{search_string}_#{category_id}_#{page}.html") end |
#execute ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/demonoid/base.rb', line 26 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
42 43 44 45 46 47 48 |
# File 'lib/demonoid/base.rb', line 42 def fetch_search_results Demonoid searchurl = "http://www.demonoid.me/files/?category=1&subcategory=All&language=0&quality=All&seeded=0&external=2&query=#{search_string}&uid=0&sort=S" Hpricot(URI.parse(searchurl).read) end |
#get_search_results ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/demonoid/base.rb', line 12 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 |