<commit_before>module RSpecXML
  module XMLMatchers
    class HaveXPath
        
      def initialize(xpath)
        self.xpath = xpath 
        @matcher = Matcher.new(:xpath => xpath)
      end 

      def with_text(text)
        @matcher = TextMatcher.new(:xpath => xpath, :text => text.to_s)
        self
      end

      def matches?(xml)
        @matcher.matches?(xml)
      end

      def failure_message_for_should
        @matcher.failure_message_for_should
      end

      def failure_message_for_should_not
        @matcher.failure_message_for_should_not
      end

      private

      attr_accessor :xpath

      class Matcher

        def initialize(options={})
          self.xpath = options[:xpath]
        end

        def matches?(xml)
          ::Nokogiri::XML(xml).xpath(@xpath).count > 0
        end

        def failure_message_for_should
          "expected #{xpath} to exist" 
        end

        def failure_message_for_should_not
          "expected #{xpath} to not exist"
        end

        private

        attr_accessor :xpath

      end<commit_msg>use attr_accessors instead of instance variables<commit_after>module RSpecXML
  module XMLMatchers
    class HaveXPath
        
      def initialize(xpath)
        self.xpath = xpath 
        self.matcher = Matcher.new(:xpath => xpath)
      end 

      def with_text(text)
        self.matcher = TextMatcher.new(:xpath => xpath, :text => text.to_s)
        self
      end

      def matches?(xml)
        matcher.matches?(xml)
      end

      def failure_message_for_should
        matcher.failure_message_for_should
      end

      def failure_message_for_should_not
        matcher.failure_message_for_should_not
      end

      private

      attr_accessor :xpath, :matcher

      class Matcher

        def initialize(options={})
          self.xpath = options[:xpath]
        end

        def matches?(xml)
          ::Nokogiri::XML(xml).xpath(@xpath).count > 0
        end

        def failure_message_for_should
          "expected #{xpath} to exist" 
        end

        def failure_message_for_should_not
          "expected #{xpath} to not exist"
        end

        private

        attr_accessor :xpath

      end
{'fraction_non_alphanumeric': 0.07097649186256781, 'fraction_numerical': 0.0009041591320072332, 'mean_word_length': 1.8928104575163398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '3601553', 'n_tokens_mistral': 682, 'n_tokens_neox': 651, 'n_words': 143}