Class: Demonoid::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/demonoid/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_string, category = 0) ⇒ Search

Returns a new instance of Search.



5
6
7
8
9
10
# File 'lib/demonoid/base.rb', line 5

def initialize(search_string, category=0)
  self.search_string = URI.encode(search_string)
  self.page = -1

  @results = Demonoid::ResultSet.new(self)
end

Instance Attribute Details

#cachingObject

Returns the value of attribute caching.



3
4
5
# File 'lib/demonoid/base.rb', line 3

def caching
  @caching
end

#category_idObject

Returns the value of attribute category_id.



3
4
5
# File 'lib/demonoid/base.rb', line 3

def category_id
  @category_id
end

#pageObject

Returns the value of attribute page.



3
4
5
# File 'lib/demonoid/base.rb', line 3

def page
  @page
end

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/demonoid/base.rb', line 3

def results
  @results
end

#search_stringObject

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_filenameObject



38
39
40
# File 'lib/demonoid/base.rb', line 38

def cached_filename
  File.join("tmp", "searches", "#{search_string}_#{category_id}_#{page}.html")
end

#executeObject



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_resultsObject



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_resultsObject



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