-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
206 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
require 'site_mapper' | ||
|
||
url = ARGV[0] | ||
SiteMapper.map(url) | ||
SiteMapper.map(url, :system) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module SiteMapper | ||
# Handles logging | ||
class Logger | ||
# @param [Symbol] type of logger class to be used | ||
def self.use_logger_type(type) | ||
fail 'Logger already set' if defined?(@@log) | ||
@@log = case type.to_s | ||
when 'nil', 'default' | ||
NilLogger | ||
when 'system' | ||
SystemOutLogger | ||
else | ||
fail ArgumentError, "Unknown logger type: '#{type}'" | ||
end | ||
@@log | ||
end | ||
|
||
# @param [Class, #log, #err_log] logger a logger class | ||
def self.use_logger(logger) | ||
fail 'Logger already set' if defined?(@@log) | ||
@@log = logger | ||
end | ||
|
||
# @param [String] msg to be logged | ||
def self.log(msg) | ||
@@log ||= use_logger_type(:default) | ||
@@log.log(msg) | ||
end | ||
|
||
# @param [String] err_msg to be logged | ||
def self.err_log(err_msg) | ||
@@log ||= use_logger_type(:default) | ||
@@log.err_log(err_msg) | ||
end | ||
|
||
# Log to terminal. | ||
module SystemOutLogger | ||
# @param [String] msg to be logged to STDOUT | ||
def self.log(msg) | ||
STDOUT.puts(msg) | ||
end | ||
|
||
# @param [String] msg to be logged to STDERR | ||
def self.err_log(msg) | ||
STDERR.puts("[ERROR] #{msg}") | ||
end | ||
end | ||
|
||
# Don't log | ||
module NilLogger | ||
# @param [String] msg to be ignored | ||
def self.log(msg);end | ||
# @param [String] msg to be ignored | ||
def self.err_log(msg);end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SiteMapper | ||
# Gem version | ||
VERSION = '0.0.10' | ||
VERSION = '0.0.11' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Queue length: 0, Parsing: https://trialbee.com/ | ||
Queue length: 19, Parsing: https://trialbee.com/studies | ||
Queue length: 18, Parsing: https://trialbee.com/services | ||
Queue length: 18, Parsing: https://trialbee.com/investigators/welcome | ||
Queue length: 19, Parsing: https://trialbee.com/news_posts | ||
Queue length: 21, Parsing: https://trialbee.com/about/index | ||
Queue length: 20, Parsing: https://trialbee.com/job_listings | ||
Queue length: 20, Parsing: https://trialbee.com/contact | ||
Queue length: 19, Parsing: https://trialbee.com/login | ||
Queue length: 19, Parsing: https://trialbee.com/patients/new | ||
Queue length: 19, Parsing: https://trialbee.com/news_posts?id=27 | ||
Queue length: 18, Parsing: https://trialbee.com/news_posts?id=26 | ||
Queue length: 17, Parsing: https://trialbee.com/news_posts?id=25 | ||
Queue length: 16, Parsing: https://trialbee.com/news_posts?id=24 | ||
Queue length: 15, Parsing: https://trialbee.com/news_posts?id=23 | ||
Queue length: 14, Parsing: https://trialbee.com/news_posts?id=22 | ||
Queue length: 13, Parsing: https://trialbee.com/studies/1137-videnskabeligt-forsog-til-patienter-med-type-2-sukkersyge?locale=dk | ||
Queue length: 13, Parsing: https://trialbee.com/studies/1137-videnskabeligt-forsog-til-patienter-med-type-2-sukkersyge | ||
Queue length: 12, Parsing: https://trialbee.com/studies/1136-en-studie-for-dig-som-har-typ-2-diabetes?locale=sv | ||
Queue length: 12, Parsing: https://trialbee.com/studies/1136-en-studie-for-dig-som-har-typ-2-diabetes | ||
Queue length: 11, Parsing: https://trialbee.com/privacy | ||
Queue length: 13, Parsing: https://trialbee.com/quotations/new.json | ||
Queue length: 12, Parsing: https://trialbee.com/investigators/new | ||
Queue length: 12, Parsing: https://trialbee.com/investigators/faq | ||
Queue length: 11, Parsing: https://trialbee.com/news_posts?page=2 | ||
Queue length: 11, Parsing: https://trialbee.com/news_posts?page=3 | ||
Queue length: 10, Parsing: https://trialbee.com/download_press_pack | ||
Queue length: 9, Parsing: https://trialbee.com/job_listings/1/job_applications/new | ||
Queue length: 8, Parsing: https://trialbee.com/forgot_password | ||
Queue length: 7, Parsing: https://trialbee.com/patients/terms | ||
Queue length: 6, Parsing: https://trialbee.com/studies/1137-videnskabeligt-forsog-til-patienter-med-type-2-sukkersyge/locations/clinics | ||
Queue length: 5, Parsing: https://trialbee.com/studies/1136-en-studie-for-dig-som-har-typ-2-diabetes/locations/clinics | ||
Queue length: 4, Parsing: https://trialbee.com/privacy?locale=en | ||
Queue length: 3, Parsing: https://trialbee.com/privacy?locale=pl | ||
Queue length: 2, Parsing: https://trialbee.com/cdn-cgi/l/email-protection | ||
Queue length: 2, Parsing: https://trialbee.com/investigators/terms | ||
Queue length: 1, Parsing: https://trialbee.com/news_posts?page=4 | ||
Queue length: 0, Parsing: https://trialbee.com//www.cloudflare.com/sign-up | ||
Crawling finished, 38 links found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'spec_helper' | ||
|
||
class TestLogger | ||
def self.log(msg);"info: #{msg}";end | ||
def self.err_log(msg);"err: #{msg}";end | ||
end | ||
|
||
describe SiteMapper::Logger do | ||
before(:all) { SiteMapper::Logger.use_logger(TestLogger) } | ||
|
||
let(:logger) { SiteMapper::Logger } | ||
let(:system_logger) { SiteMapper::Logger::SystemOutLogger } | ||
let(:nil_logger) { SiteMapper::Logger::NilLogger } | ||
|
||
describe 'has NilLogger' do | ||
it 'has class' do | ||
expect { nil_logger }.not_to raise_error | ||
end | ||
|
||
it 'reponds to #log' do | ||
expect(nil_logger).to respond_to(:log) | ||
end | ||
|
||
it 'reponds to #err_log' do | ||
expect(nil_logger).to respond_to(:err_log) | ||
end | ||
end | ||
|
||
describe 'SystemOutLogger' do | ||
it 'has class' do | ||
expect { system_logger }.not_to raise_error | ||
end | ||
|
||
# Should work but doesn't.. | ||
# it '#log logs to STDOUT' do | ||
# expect { system_logger.log('log_message') }.to output('log_message').to_stdout | ||
# end | ||
|
||
# Should work but doesn't.. | ||
# it '#err_log logs to STDERR' do | ||
# expect { system_logger.err_log('log_message') }.to output('[ERROR] log_message').to_stderr | ||
# end | ||
|
||
it 'reponds to #log' do | ||
expect(system_logger).to respond_to(:log) | ||
end | ||
|
||
it 'reponds to #err_log' do | ||
expect(system_logger).to respond_to(:err_log) | ||
end | ||
end | ||
|
||
describe '#log' do | ||
it 'calls log' do | ||
expect { logger.log('asd') }.not_to raise_error | ||
end | ||
end | ||
|
||
describe '#err_log' do | ||
it 'calls err_log' do | ||
expect { logger.err_log('asd') }.not_to raise_error | ||
end | ||
end | ||
|
||
describe '#use_logger' do | ||
it 'can set custom logger' do | ||
expect(logger.log('log')).to eq 'info: log' | ||
expect(logger.err_log('log')).to eq 'err: log' | ||
end | ||
|
||
it 'raises exception if logger already has been set' do | ||
expect do | ||
logger.use_logger_type(:system) | ||
logger.use_logger(TestLogger) | ||
end.to raise_error | ||
end | ||
end | ||
end |