Class: SiteCrawler

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/site_crawler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_paths = ['/']) ⇒ SiteCrawler

Returns a new instance of SiteCrawler.



10
11
12
13
14
15
# File 'lib/site_crawler.rb', line 10

def initialize(start_paths=['/'])
  self.start_paths = start_paths
  self.saved_paths = []
  self.queued_paths= []
  capybara_setup
end

Instance Attribute Details

#current_pathObject

Returns the value of attribute current_path.



8
9
10
# File 'lib/site_crawler.rb', line 8

def current_path
  @current_path
end

#current_path_bangObject

Returns the value of attribute current_path_bang.



8
9
10
# File 'lib/site_crawler.rb', line 8

def current_path_bang
  @current_path_bang
end

#queued_pathsObject

Returns the value of attribute queued_paths.



8
9
10
# File 'lib/site_crawler.rb', line 8

def queued_paths
  @queued_paths
end

#saved_pathsObject

Returns the value of attribute saved_paths.



8
9
10
# File 'lib/site_crawler.rb', line 8

def saved_paths
  @saved_paths
end

#start_pathsObject

Returns the value of attribute start_paths.



8
9
10
# File 'lib/site_crawler.rb', line 8

def start_paths
  @start_paths
end

Instance Method Details

#crawl(paths) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/site_crawler.rb', line 22

def crawl(paths)
  paths.each do |path|
    @current_path = path
    @current_path_bang = "#!#{@current_path}"
    if !saved_paths.include? @current_path
      visit_page
      save_page
    end
  end
  queued_paths.present? ? crawl(queued_paths) : done_message
end

#start_crawlObject



17
18
19
20
# File 'lib/site_crawler.rb', line 17

def start_crawl
  start_message
  crawl(@start_paths)
end