Class: BBC::A11y::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/bbc/a11y/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin, stdout, stderr, args) ⇒ CLI

Returns a new instance of CLI.



13
14
15
# File 'lib/bbc/a11y/cli.rb', line 13

def initialize(stdin, stdout, stderr, args)
  @stdin, @stdout, @stderr, @args = stdin, stdout, stderr, args
end

Instance Method Details

#all_pages_tested(summary) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bbc/a11y/cli.rb', line 46

def all_pages_tested(summary)
  messages = [
    summary_message(summary.pages, 'page', 'checked'),
    summary_message(summary.errors, 'error', 'found'),
    summary_message(summary.skips, 'standard', 'skipped')
  ]
  stdout.puts(messages.join(', '))
  @any_errors = summary.fail?
  unless @any_errors
    stdout.puts NO_ERRORS_MESSAGE
  end
end

#callObject



17
18
19
20
21
22
23
24
# File 'lib/bbc/a11y/cli.rb', line 17

def call
  Runner.new(settings, self).run
  exit 1 if @any_errors
rescue Configuration::ParseError => error
  exit_with_message error.message
rescue Configuration::MissingConfigurationFileError => error
  exit_with_message error.message
end

#page_tested(page_settings, lint_result) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bbc/a11y/cli.rb', line 26

def page_tested(page_settings, lint_result)
  if lint_result.passed?
    stdout.puts green("#{page_settings.url}")
  else
    stdout.puts red("#{page_settings.url}")
    current_section = nil
    current_name = nil
    lint_result.errors.each do |error|
      if error.section != current_section || error.name != current_name
        humanised_section = humanise(error.section)
        stdout.puts "  * #{humanised_section}: #{error.name}"
      end
      stdout.puts "    - #{error.message}"
      current_section = error.section
      current_name = error.name
    end
  end
  stdout.puts ""
end