class AudioBookCreator::Spider

Attributes

page_def[RW]
web[RW]

@!attribute web

@return Hash access to the world wide web

Public Class Methods

new(page_def, web) click to toggle source
# File lib/audio_book_creator/spider.rb, line 11
def initialize(page_def, web)
  @page_def     = page_def
  @web          = web
end

Public Instance Methods

run(chapters) click to toggle source
# 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

Private Instance Methods

visit_page(url) click to toggle source

this one hangs on mutations

# File lib/audio_book_creator/spider.rb, line 36
def visit_page(url)
  logger.info { "visit #{url}" }
  WebPage.new(url, web[url.to_s])
end