Class: E621::Search

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

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Search

commands update/download



26
27
28
29
30
31
# File 'lib/search.rb', line 26

def initialize(query)
  @api,@mt      = API.new("post"),Mutex.new
  @bad_tags     = /(\s|^)(#{Config.blacklist.map{|x|Regexp.escape(x)}.join("|")})(\s|$)/
  @request = {"limit"=>100,"page"=>1,"tags"=>query.join("+")}
  fetch
end

Instance Method Details

#each_postObject



38
39
40
41
42
43
44
45
# File 'lib/search.rb', line 38

def each_post
  while @posts != Array.new do
    @posts.each do |post|
      yield post
    end
    next!
  end
end

#next!Object



33
34
35
36
# File 'lib/search.rb', line 33

def next!
  @request["page"] += 1
  fetch
end

#pageObject



47
48
49
# File 'lib/search.rb', line 47

def page
  return @request["page"]
end

#page=(page) ⇒ Object



51
52
53
54
# File 'lib/search.rb', line 51

def page=(page)
  @request["page"]=page
  fetch
end

#previous!Object



56
57
58
59
# File 'lib/search.rb', line 56

def previous!
  @request["page"] -= 1
  fetch
end

#to_json(a = nil, b = nil) ⇒ Object



61
62
63
64
# File 'lib/search.rb', line 61

def to_json(a=nil,b=nil)
  posts = @posts.map{|o|o.to_json}
  {"name"=>@name,"queries"=>@queries,"posts"=>posts}.to_json
end