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, logger, cache, options) ⇒ Check

Returns a new instance of Check.



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

def initialize(src, path, html, logger, cache, options)
  @src    = src
  @path   = path
  @html   = remove_ignored(html)
  @logger = logger
  @cache = cache
  @options = options
  @issues = []
  @internal_urls = {}
  @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

#internal_urlsObject (readonly)

Returns the value of attribute internal_urls.



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

def internal_urls
  @internal_urls
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



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/html-proofer/check.rb', line 52

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



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

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

#add_to_external_urls(url) ⇒ Object



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

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

  if @external_urls[url]
    @external_urls[url] << @path
  else
    @external_urls[url] = [@path]
  end
end

#add_to_internal_urls(url, internal_url) ⇒ Object



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

def add_to_internal_urls(url, internal_url)
  if @internal_urls[url]
    @internal_urls[url] << internal_url
  else
    @internal_urls[url] = [internal_url]
  end
end

#blank?(attr) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/html-proofer/check.rb', line 64

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

#create_element(node) ⇒ Object



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

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

#runObject

Raises:

  • (NotImplementedError)


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

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