Class: SiteCrawler
- Inherits:
-
Object
- Object
- SiteCrawler
- Includes:
- Capybara::DSL
- Defined in:
- lib/site_crawler.rb
Instance Attribute Summary collapse
-
#current_path ⇒ Object
Returns the value of attribute current_path.
-
#current_path_bang ⇒ Object
Returns the value of attribute current_path_bang.
-
#queued_paths ⇒ Object
Returns the value of attribute queued_paths.
-
#saved_paths ⇒ Object
Returns the value of attribute saved_paths.
-
#start_paths ⇒ Object
Returns the value of attribute start_paths.
Instance Method Summary collapse
- #crawl(paths) ⇒ Object
-
#initialize(start_paths = ['/']) ⇒ SiteCrawler
constructor
A new instance of SiteCrawler.
- #start_crawl ⇒ Object
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= [] end |
Instance Attribute Details
#current_path ⇒ Object
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_bang ⇒ Object
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_paths ⇒ Object
Returns the value of attribute queued_paths.
8 9 10 |
# File 'lib/site_crawler.rb', line 8 def queued_paths @queued_paths end |
#saved_paths ⇒ Object
Returns the value of attribute saved_paths.
8 9 10 |
# File 'lib/site_crawler.rb', line 8 def saved_paths @saved_paths end |
#start_paths ⇒ Object
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) : end |
#start_crawl ⇒ Object
17 18 19 20 |
# File 'lib/site_crawler.rb', line 17 def start_crawl crawl(@start_paths) end |