Class: Html::Test::LinkValidator

Inherits:
Object
  • Object
show all
Includes:
Assertions, UrlSelector, Test::Unit::Assertions
Defined in:
lib/link_validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  self.start_url = strip_anchor(url)

  # Default values for options
  if Object.const_defined?(:RailsTidy)
    self.options[:validators] = %w(tidy)
  else
    self.options[:validators] = %w(w3c)      
  end
  self.options[:skip_patterns] = []
  self.options[:follow_external] = true
  self.options[:follow_links] = true
  self.options[:quiet] = false
  Html::Test::Validator.dtd = options[:dtd] if options[:dtd]

  self.options.merge!(options)
  
  validate_links
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



12
13
14
# File 'lib/link_validator.rb', line 12

def log
  @log
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/link_validator.rb', line 12

def options
  @options
end

#start_urlObject

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(options_array)
  if options_array[0] !~ /:\/\//
    raise "First argument must be URL, i.e. http://my.url.com"
  end

  options = {}

  opts = OptionParser.new
  opts.on("--no-follow") { options[:follow_links] = false }
  opts.on("--validators validators") do |validators|
    options[:validators] = validators.split(",")
  end
  opts.on('--dtd DTD') { |dtd| options[:dtd] = dtd }
  opts.on("--skip skip_patterns") do |skip_patterns|
    options[:skip_patterns] = skip_patterns.split(",").map { |p| Regexp.new(p) }
  end
  opts.on("--only only_pattern") do |only_pattern|
    options[:only_pattern] = Regexp.new(only_pattern)
  end
  opts.on('--no-external') { options[:follow_external] = false }
  opts.on('--quiet') { options[:quiet] = true }
  
  opts.parse!(options_array)

  options
end