Module: Scrapetor::URL

Defined in:
lib/scrapetor/url.rb

Constant Summary collapse

ABSOLUTE =
%r{\A[a-zA-Z][\w+.\-]*://}.freeze

Class Method Summary collapse

Class Method Details

.absolute(href, base = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/scrapetor/url.rb', line 9

def self.absolute(href, base = nil)
  return nil if href.nil?
  h = href.to_s
  return h if h.match?(ABSOLUTE)
  return h if base.nil?
  begin
    URI.join(base.to_s, h).to_s
  rescue URI::InvalidURIError, ArgumentError
    h
  end
end