<commit_before>require 'json'

class SiteInspector
  class Endpoint
    class Accessibility < Check
      
      def section508
        pa11y(:section508)
      end
      
      def wcag2a
        pa11y(:wcag2a)
      end
      
      def wcag2aa
        pa11y(:wcag2aa)
      end
      
      def wcag2aaa
        pa11y(:wcag2aaa)
      end
      
      private
      
      def pa11y(standard)
        standards = {
          section508: 'Section508',
          wcag2a: 'WCAG2A',
          wcag2aa: 'WCAG2AA',
          wcag2aaa: 'WCAG2AAA'
        }
        standard = standards[standard]
                
        json_string = `pa11y #{host} -s #{standard} -r json`
        JSON.parse(json_string)
      end
      
    end
  end
end<commit_msg>Using popen3 to shell out to pa11y<commit_after>require 'json'
require 'open3'

class SiteInspector
  class Endpoint
    class Accessibility < Check
      
      def section508
        pa11y(:section508)
      end
      
      def wcag2a
        pa11y(:wcag2a)
      end
      
      def wcag2aa
        pa11y(:wcag2aa)
      end
      
      def wcag2aaa
        pa11y(:wcag2aaa)
      end
      
      private
      
      def pa11y(standard)
        standards = {
          section508: 'Section508',
          wcag2a: 'WCAG2A',
          wcag2aa: 'WCAG2AA',
          wcag2aaa: 'WCAG2AAA'
        }
        standard = standards[standard]
                             
        cmd = "pa11y #{endpoint.uri} -s #{standard} -r json"
        response = ""
        error = nil
        
        Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
          response = stdout.read
          error = stderr.read          
        end    
        
        if error
          raise error
        end
        
        JSON.parse(response) 
      end
      
    end
  end
end
{'fraction_non_alphanumeric': 0.0710352422907489, 'fraction_numerical': 0.042951541850220265, 'mean_word_length': 1.2655860349127181, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '121326', 'n_tokens_mistral': 631, 'n_tokens_neox': 588, 'n_words': 128}