Class: StyleScanner::SentenceScans::BrokenLink

Inherits:
Base
  • Object
show all
Defined in:
lib/style_scanner/sentence_scans/broken_link.rb

Constant Summary collapse

URL_REGEX =
/(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?/

Instance Attribute Summary

Attributes inherited from Base

#sentence

Instance Method Summary collapse

Methods inherited from Base

#initialize, load_file, scan

Constructor Details

This class inherits a constructor from StyleScanner::SentenceScans::Base

Instance Method Details

#scanObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/style_scanner/sentence_scans/broken_link.rb', line 7

def scan
  links = sentence.scan(URL_REGEX)
  links.each do |url|
    begin
      attempt_to_visit_url(url)
      # socket error occurs if link is bad
    rescue SocketError, Errno::ECONNREFUSED
      create_problem("Url #{url} does not work")
    end
  end
end