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.

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.


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

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


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def element
  @element
end

#external_urlsObject (readonly)

Returns the value of attribute external_urls


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def external_urls
  @external_urls
end

#htmlObject (readonly)

Returns the value of attribute html


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def html
  @html
end

#issuesObject (readonly)

Returns the value of attribute issues


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def issues
  @issues
end

#nodeObject (readonly)

Returns the value of attribute node


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def node
  @node
end

#optionsObject (readonly)

Returns the value of attribute options


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def path
  @path
end

#srcObject (readonly)

Returns the value of attribute src


6
7
8
# File 'lib/html-proofer/check.rb', line 6

def src
  @src
end

Class Method Details

.subchecksObject


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

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,, content: nil) ⇒ Object


26
27
28
# File 'lib/html-proofer/check.rb', line 26

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

#add_path_for_url(url) ⇒ Object


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

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


30
31
32
33
# File 'lib/html-proofer/check.rb', line 30

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

#blank?(attr) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/html-proofer/check.rb', line 54

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

#create_element(node) ⇒ Object


17
18
19
20
# File 'lib/html-proofer/check.rb', line 17

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

#runObject

Raises:

  • (NotImplementedError)

22
23
24
# File 'lib/html-proofer/check.rb', line 22

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