Sha256: b7c03ba7c461b3b3b19c8d66e806d8efd9bb8ff6575a537f544364b1ce7b09a8

Contents?: true

Size: 871 Bytes

Versions: 2

Compression:

Stored size: 871 Bytes

Contents

require 'entree'
require 'oj'

module Entree
  class Audit
    attr_reader :target

    def initialize(target)
      @target = target
    end

    def run
      perform_audit
    end

    def runner
      @runner ||= Runner.new(self.target)
    end

    private

    def perform_audit
      runner.run
      @output = runner.output
      parse_output
    end

    def parse_output
      # refactor into new class
      raw_results = Oj.load(@output).map {|record|
        if record["code"][0..3] == "WCAG"
          record["code"].match /(WCAG2A+\.\w+?\.Guideline(\d_\d)\.\2_\d)\.((?:[A-Z]+\d+,?)+)/
          record["code"] = $1
          record["infractions"] = $3.split /,/
        end

        record
      }

      @results = raw_results.group_by { |result| result['type'] }
    rescue Exception => e
      raise Entree::ParserError.new(e.message)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
entree-0.0.3 lib/entree/audit.rb
entree-0.0.2 lib/entree/audit.rb