Class: E621::Search

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

Instance Method Summary collapse

Constructor Details

#initialize(query, page = 1) ⇒ Search

commands update/download



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

def initialize(query,page=1)
  @api, @queue  = API.new, SizedQueue.new(4096)
  @request      = {limit:100,page:page,tags:query.url_encode}
end

Instance Method Details

#each_post ⇒ Object

Return each post via a block and process them individually. This could cause a race condition in the unlikely manner when the queue is empty and not being filled again, but the worker is still runnning.



41
42
43
44
45
46
47
48
49
# File 'lib/search.rb', line 41

def each_post
  fetch_all
  until !@worker.status do
    until @queue.empty? do
      post = @queue.pop
      yield post
    end
  end
end

#next_page ⇒ Object



31
32
33
# File 'lib/search.rb', line 31

def next_page
  @request[:page] += 1
end

#page ⇒ Object



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

def page
  return @request[:page]
end

#page=(page) ⇒ Object



59
60
61
# File 'lib/search.rb', line 59

def page=(page)
  @request[:page] = page
end

#posts ⇒ Object



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

def posts
  fetch
end

#previous_page ⇒ Object



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

def previous_page
  @request[:page] -= 1
end