Class: NSAStorage::Crawl
- Inherits:
-
Object
- Object
- NSAStorage::Crawl
- Defined in:
- lib/nsastorage/crawl.rb
Overview
Handles the crawl command via CLI.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr, url: nil) ⇒ Crawl
constructor
A new instance of Crawl.
- #process(url:) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr, url: nil) ⇒ Crawl
Returns a new instance of Crawl.
13 14 15 16 17 |
# File 'lib/nsastorage/crawl.rb', line 13 def initialize(stdout: $stdout, stderr: $stderr, url: nil) @stdout = stdout @stderr = stderr @url = url end |
Class Method Details
.run ⇒ Object
6 7 8 |
# File 'lib/nsastorage/crawl.rb', line 6 def self.run(...) new(...).run end |
Instance Method Details
#process(url:) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/nsastorage/crawl.rb', line 31 def process(url:) @stdout.puts(url) facility = Facility.fetch(url: url) @stdout.puts(facility.text) facility.prices.each { |price| @stdout.puts(price.text) } @stdout.puts rescue FetchError => e @stderr.puts("url=#{url} error=#{e.message}") end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nsastorage/crawl.rb', line 19 def run if @url process(url: @url) else sitemap = Facility.sitemap @stdout.puts("count=#{sitemap.links.count}") @stdout.puts sitemap.links.each { |link| process(url: link.loc) } end end |