Class: Html::Test::LinkValidator
- Inherits:
-
Object
- Object
- Html::Test::LinkValidator
- Includes:
- Assertions, UrlSelector, Test::Unit::Assertions
- Defined in:
- lib/link_validator.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
-
#options ⇒ Object
Returns the value of attribute options.
-
#start_url ⇒ Object
Returns the value of attribute start_url.
Class Method Summary collapse
-
.parse_command_line(options_array) ⇒ Object
Generates an options hash from the command line options.
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ LinkValidator
constructor
A new instance of LinkValidator.
Methods included from UrlSelector
#anchor_urls, #external_http?, #form_urls, #has_protocol?, #http_protocol?, #image_urls, #response_body, #select, #skip_url?, #special_url?, #unsupported_protocol?
Methods included from Assertions
#assert_tidy, #assert_validates, #assert_w3c, #assert_xmllint
Constructor Details
#initialize(url, options = {}) ⇒ LinkValidator
Returns a new instance of LinkValidator.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/link_validator.rb', line 22 def initialize(url, = {}) self.start_url = strip_anchor(url) # Default values for options if Object.const_defined?(:RailsTidy) self.[:validators] = %w(tidy) else self.[:validators] = %w(w3c) end self.[:skip_patterns] = [] self.[:follow_external] = true self.[:follow_links] = true self.[:quiet] = false Html::Test::Validator.dtd = [:dtd] if [:dtd] self..merge!() validate_links end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
12 13 14 |
# File 'lib/link_validator.rb', line 12 def log @log end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/link_validator.rb', line 12 def @options end |
#start_url ⇒ Object
Returns the value of attribute start_url.
12 13 14 |
# File 'lib/link_validator.rb', line 12 def start_url @start_url end |
Class Method Details
.parse_command_line(options_array) ⇒ Object
Generates an options hash from the command line options
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/link_validator.rb', line 43 def self.parse_command_line() if [0] !~ /:\/\// raise "First argument must be URL, i.e. http://my.url.com" end = {} opts = OptionParser.new opts.on("--no-follow") { [:follow_links] = false } opts.on("--validators validators") do |validators| [:validators] = validators.split(",") end opts.on('--dtd DTD') { |dtd| [:dtd] = dtd } opts.on("--skip skip_patterns") do |skip_patterns| [:skip_patterns] = skip_patterns.split(",").map { |p| Regexp.new(p) } end opts.on("--only only_pattern") do |only_pattern| [:only_pattern] = Regexp.new(only_pattern) end opts.on('--no-external') { [:follow_external] = false } opts.on('--quiet') { [:quiet] = true } opts.parse!() end |