<commit_before>module OptimusPrime
  module Transformers
    class RecordFilter < Destination

      def initialize(constraints:)
        @rules = constraints
      end

      def write(record)
        push(record) if valid?(record)
      end

      private

      def valid?(record)
        @rules.all? { |field, rule| send(rule[:type], record[field], rule[:values]) }
      end

      def range(value, params)
        value && value >= params[0] && value <= params[1]
      end

      def less_than_or_equal(value, params)
        value && value <= params[0]
      end

      def less_than(value, params)
        value && value < params[0]
      end

      def greater_than_or_equal(value, params)
        value && value >= params[0]
      end

      def greater_than(value, params)
        value && value > params[0]
      end

      def set(value, params)
        params.include? value
      end

    end
  end
end<commit_msg>add #contained and #not_contained into RecordFilter transformer<commit_after>module OptimusPrime
  module Transformers
    class RecordFilter < Destination
      def initialize(constraints:)
        @rules = constraints
      end

      def write(record)
        push(record) if valid?(record)
      end

      private

      def valid?(record)
        @rules.all? { |field, rule| send(rule[:type], record[field], rule[:values]) }
      end

      def range(value, params)
        value && value >= params[0] && value <= params[1]
      end

      def less_than_or_equal(value, params)
        value && value <= params[0]
      end

      def less_than(value, params)
        value && value < params[0]
      end

      def greater_than_or_equal(value, params)
        value && value >= params[0]
      end

      def greater_than(value, params)
        value && value > params[0]
      end

      def set(value, params)
        params.include? value
      end

      def contained(value, params)
        params.any? { |p| value.include?(p) }
      end

      def not_contained(value, params)
        params.none? { |p| value.include?(p) }
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10205054840247973, 'fraction_numerical': 0.005722460658082976, 'mean_word_length': 2.1360239162929746, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4035010', 'n_tokens_mistral': 632, 'n_tokens_neox': 605, 'n_words': 167}