class RayyanScrapers::Stubber
Public Class Methods
stub_prediction()
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 51 def self.stub_prediction allow_any_instance_of(PredictionModelTrainJob).to receive(:run).and_return(nil) end
stub_pubmed(set_id)
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 10 def self.stub_pubmed(set_id) sets = [2, 5, 50] raise "set_id argument should be one of #{sets.inspect}" unless sets.include? set_id # Rails.logger.info "Stubbing PubMed..." base_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi" stub_request_with_file(self.stubbed_root.join("pubmed-search-#{set_id}.xml"), Regexp.new(base_url)) end
stub_pubmed_details()
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 21 def self.stub_pubmed_details # Rails.logger.info "Stubbing PubMed details..." base_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmode=xml" DirIterator.new(self.stubbed_root).iterate do |file| pmid = file.match(/.*pubmed-([0-9]+).xml/)[1] regex = "#{base_url}.*&id=#{pmid}" stub_request_with_file(file, Regexp.new(regex)) # Rails.logger "stubbed #{regex} with #{file}" end end
stub_pubmed_refs()
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 32 def self.stub_pubmed_refs # Rails.logger.info "Stubbing PubMed references..." base_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi?dbfrom=pubmed&db=pubmed&id=" DirIterator.new(self.stubbed_root.join("refs")).iterate do |file| pmid = file.match(/.*pubmed-refs-([0-9]+).xml/)[1] stub_request_with_file(file, "#{base_url}#{pmid}") end # 100029 # 1000147 # 4589401 # 10029499 # 10051785 # 10052380 # 10052444 end
stub_request_with_body(body, url)
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 63 def self.stub_request_with_body(body, url) response = Typhoeus::Response.new(code: 200, body: body) Typhoeus.stub(url).and_return(response) response end
stub_request_with_error(code, url)
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 69 def self.stub_request_with_error(code, url) response = Typhoeus::Response.new(code: code) Typhoeus.stub(url).and_return(response) response end
stub_request_with_file(filename, url)
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 59 def self.stub_request_with_file(filename, url) stub_request_with_body File.read(filename), url end
stubbed_root()
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 6 def self.stubbed_root Pathname.new File.expand_path("../../../spec/support/stubbed", __FILE__) end
unstub_prediction()
click to toggle source
# File lib/rayyan-scrapers/stubber.rb, line 55 def self.unstub_prediction allow_any_instance_of(PredictionModelTrainJob).to receive(:run).and_call_original end