Class: PdfLinksChecker::URL
- Inherits:
-
Object
- Object
- PdfLinksChecker::URL
- Defined in:
- lib/pdf_links_checker/url.rb
Instance Method Summary collapse
-
#initialize(pdf_link) ⇒ URL
constructor
A new instance of URL.
- #invalid? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(pdf_link) ⇒ URL
Returns a new instance of URL.
7 8 9 |
# File 'lib/pdf_links_checker/url.rb', line 7 def initialize(pdf_link) @pdf_link = pdf_link end |
Instance Method Details
#invalid? ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pdf_links_checker/url.rb', line 11 def invalid? begin uri = to_s rescue PdfLinksChecker::InvalidLink => e return false end url = URI.parse(uri) req = Net::HTTP.new(url.host, url.port) req.use_ssl = true if uri.include?("https") begin res = req.request_head(url.path) return true if res.code == "404" rescue StandardError => e return true end false end |
#to_s ⇒ Object
32 33 34 35 36 |
# File 'lib/pdf_links_checker/url.rb', line 32 def to_s a = pdf_link[:A] raise PdfLinksChecker::InvalidLink.new('Invalid Link') unless a.respond_to?(:key?) && a.key?(:URI) a[:URI] end |