Class: AudioBookCreator::Spider

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/audio_book_creator/spider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(page_def, web) ⇒ Spider

Returns a new instance of Spider.



11
12
13
14
# File 'lib/audio_book_creator/spider.rb', line 11

def initialize(page_def, web)
  @page_def     = page_def
  @web          = web
end

Instance Attribute Details

#page_defObject

Returns the value of attribute page_def.



9
10
11
# File 'lib/audio_book_creator/spider.rb', line 9

def page_def
  @page_def
end

#webObject

Returns Hash access to the world wide web.

Returns:

  • Hash access to the world wide web



7
8
9
# File 'lib/audio_book_creator/spider.rb', line 7

def web
  @web
end

Instance Method Details

#run(chapters) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/audio_book_creator/spider.rb', line 16

def run(chapters)
  outstanding = CascadingArray.new([], WebPage.map_urls(chapters))
  visited = []

  while (url = outstanding.shift)
    wp = visit_page(url)
    visited << wp
    page_def.page_links(wp).each do |href|
      outstanding.add_unique_page(href)
    end
    page_def.chapter_links(wp).each do |href|
      outstanding.add_unique_chapter(href)
    end
  end
  visited
end