Class: HTMLProofer::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/html-proofer/check.rb

Overview

Mostly handles issue management and collecting of external URLs.

Direct Known Subclasses

FaviconCheck, HtmlCheck, ImageCheck, LinkCheck, ScriptCheck

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, path, html, options) ⇒ Check

Returns a new instance of Check.


6
7
8
9
10
11
12
13
# File 'lib/html-proofer/check.rb', line 6

def initialize(src, path, html, options)
  @src    = src
  @path   = path
  @html   = remove_ignored(html)
  @options = options
  @issues = []
  @external_urls = {}
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def element
  @element
end

#external_urlsObject (readonly)

Returns the value of attribute external_urls


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def external_urls
  @external_urls
end

#issuesObject (readonly)

Returns the value of attribute issues


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def issues
  @issues
end

#nodeObject (readonly)

Returns the value of attribute node


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def node
  @node
end

#optionsObject (readonly)

Returns the value of attribute options


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def path
  @path
end

#srcObject (readonly)

Returns the value of attribute src


4
5
6
# File 'lib/html-proofer/check.rb', line 4

def src
  @src
end

Class Method Details

.subchecksObject


41
42
43
44
45
46
47
48
49
50
# File 'lib/html-proofer/check.rb', line 41

def self.subchecks
  classes = []

  ObjectSpace.each_object(Class) do |c|
    next unless c.superclass == self
    classes << c
  end

  classes
end

Instance Method Details

#add_issue(desc, line: nil, status: -1)) ⇒ Object


24
25
26
# File 'lib/html-proofer/check.rb', line 24

def add_issue(desc, line: nil, status: -1)
  @issues << Issue.new(@path, desc, line: line, status: status)
end

#add_path_for_url(url) ⇒ Object


33
34
35
36
37
38
39
# File 'lib/html-proofer/check.rb', line 33

def add_path_for_url(url)
  if @external_urls[url]
    @external_urls[url] << @path
  else
    @external_urls[url] = [@path]
  end
end

#add_to_external_urls(url, _) ⇒ Object


28
29
30
31
# File 'lib/html-proofer/check.rb', line 28

def add_to_external_urls(url, _)
  return if @external_urls[url]
  add_path_for_url(url)
end

#blank?(attr) ⇒ Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/html-proofer/check.rb', line 52

def blank?(attr)
  attr.nil? || attr.empty?
end

#create_element(node) ⇒ Object


15
16
17
18
# File 'lib/html-proofer/check.rb', line 15

def create_element(node)
  @node = node
  Element.new(node, self)
end

#runObject


20
21
22
# File 'lib/html-proofer/check.rb', line 20

def run
  fail NotImplementedError, 'HTMLProofer::Check subclasses must implement #run'
end