Class: Google::Scholar::ArticleEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google/scholar/article_enumerator.rb

Instance Method Summary collapse

Constructor Details

#initialize(scraper) ⇒ ArticleEnumerator

Returns a new instance of ArticleEnumerator.



6
7
8
9
10
# File 'lib/google/scholar/article_enumerator.rb', line 6

def initialize(scraper)
  @scraper = scraper
  @documents = scraper.documents
  self
end

Instance Method Details

#eachObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/google/scholar/article_enumerator.rb', line 11

def each
  current_document = @documents.first
  i = 1
  while(current_document)
    current_document.articles.each {|article| yield(article)}
    if(@documents.length > i)
      current_document = @documents[i]
    else
      if(@scraper.has_more_pages?)
        @scraper.load_next_page
        @documents = @scraper.documents
        current_document = @documents[i]
      else
        current_document = nil
      end
    end
    i += 1
  end
end