<commit_before># Copyright (C) 2016 <NAME>
# All rights reserved.
#
# This software may be modified and distributed under the
# terms of the three-clause BSD license. See LICENSE.txt
# (located in root directory of this project) for details.

require_relative './mismatch'
require_relative './falsy'

module Lextacular
  class MatchWrapper
    include Falsy

    attr_reader :given_class, :wrap_class, :matcher, :name, :temp, :defs

    def initialize wrap_class, matcher, name: nil, temp: nil, defs: nil
      @given_class = wrap_class
      @wrap_class  = defs ? Class.new(wrap_class, &defs) : wrap_class
      @matcher     = matcher
      @name        = name
      @temp        = temp
      @defs        = defs
    end

    def rename new_name
      self.class.new(
        @given_class,
        @matcher,
        name: new_name,
        temp: @temp,
        defs: defs
      )
    end

    def call string, index = 0
      found = @matcher.call(string, index)

      if found.is_a?(Mismatch)
        found
      elsif found
        @wrap_class.new(*found, name: @name, temp: @temp)
      else
        Mismatch.new(string, index)
      end
    end

    def == other
      other.is_a?(MatchWrapper) &&
      falsy_or_equal?(other.given_class, @given_class) &&
      falsy_or_equal?(other.matcher,     @matcher) &&
      falsy_or_equal?(other.name,        @name) &&
      falsy_or_equal?(other.temp,        @temp) &&
      falsy_or_equal?(other.defs,        @defs)
    end
  end
end<commit_msg>Remove unnecessarily complicated equality checks<commit_after># Copyright (C) 2016 <NAME>
# All rights reserved.
#
# This software may be modified and distributed under the
# terms of the three-clause BSD license. See LICENSE.txt
# (located in root directory of this project) for details.

require_relative './mismatch'
require_relative './falsy'

module Lextacular
  class MatchWrapper
    include Falsy

    attr_reader :given_class, :wrap_class, :matcher, :name, :temp, :defs

    def initialize wrap_class, matcher, name: nil, temp: nil, defs: nil
      @given_class = wrap_class
      @wrap_class  = defs ? Class.new(wrap_class, &defs) : wrap_class
      @matcher     = matcher
      @name        = name
      @temp        = temp
      @defs        = defs
    end

    def rename new_name
      self.class.new(
        @given_class,
        @matcher,
        name: new_name,
        temp: @temp,
        defs: defs
      )
    end

    def call string, index = 0
      found = @matcher.call(string, index)

      if found.is_a?(Mismatch)
        found
      elsif found
        @wrap_class.new(*found, name: @name, temp: @temp)
      else
        Mismatch.new(string, index)
      end
    end

    # MatchWrappers are equal if all their instance variables are the same.
    def == other
      other.is_a?(MatchWrapper) &&
      other.given_class == @given_class &&
      other.matcher == @matcher &&
      falsy_or_equal?(other.name, @name) &&
      falsy_or_equal?(other.temp, @temp) &&
      falsy_or_equal?(other.defs, @defs)
    end
  end
end
{'fraction_non_alphanumeric': 0.09914642153644124, 'fraction_numerical': 0.003282994090610637, 'mean_word_length': 2.366850828729282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5766875', 'n_tokens_mistral': 1016, 'n_tokens_neox': 998, 'n_words': 272}