Class: Checker::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/checker/html.rb

Class Method Summary collapse

Class Method Details

.compile_html_target(inspection) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/checker/html.rb', line 7

def self.compile_html_target(inspection)
  target = inspection.target
  raise 'Target is required' if target.blank?

  case inspection.type
    when 'DeclaresTag'       then target.value
    when 'DeclaresAttribute' then "@#{target.value}"
    else raise "Unsupported inspection #{inspection.type}"
  end
end

.compile_scope(binding) ⇒ Object



18
19
20
# File 'lib/checker/html.rb', line 18

def self.compile_scope(binding)
  "//#{binding == '*' ? '' : binding}"
end

.run(document, expectation, binding) ⇒ Object



3
4
5
# File 'lib/checker/html.rb', line 3

def self.run(document, expectation, binding)
  document.xpath "#{compile_scope binding}//#{compile_html_target expectation.inspection}"
end