Class: Aviary::Search

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Search

Returns a new instance of Search.



5
6
7
8
9
# File 'lib/aviary/search.rb', line 5

def initialize(config)
  @twitter      = Twitter::Search.new.filter('links').no_retweets.per_page(100).containing(config[:query])
  @limit        = config[:limit] || 50
  @current_page = 1
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



3
4
5
# File 'lib/aviary/search.rb', line 3

def current_page
  @current_page
end

#limitObject (readonly)

Returns the value of attribute limit.



3
4
5
# File 'lib/aviary/search.rb', line 3

def limit
  @limit
end

#twitterObject (readonly)

Returns the value of attribute twitter.



3
4
5
# File 'lib/aviary/search.rb', line 3

def twitter
  @twitter
end

Instance Method Details

#next_page!Object



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

def next_page!
  @current_page += 1
end

#next_page?Boolean

True if there is another page to fetch from Twitter and we haven’t exceeded the limit.

Returns boolean.

Returns:

  • (Boolean)


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

def next_page?
  self.twitter.next_page? && self.current_page < self.limit
end

#processObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/aviary/search.rb', line 11

def process
  return unless next_page?
  self.twitter.each do |status|
    ImageHost.available.each do |image_host|
      image_host.match_and_create(status)
    end
  end
  next_page!
  process
end