<commit_before>require "fuzzy_record/version"

module FuzzyRecord
  module ClassMethods
    def fuzzy_search(args)
      if args.is_a? Hash
        search = args.map{|k,v| {k => generalize(v)}}.inject(:merge)
      else
        [:fuzzy_name, :ident, :name].each do |field|
          search = {field => args}
          break if self.respond_to?(field)
        end
      end
      self.select{ |record| search.map{|k,v| record.send(k) =~ v}.inject(:|)}
    end
    private
    def generalize(str)
      return /.*#{str.gsub(/[^a-zA-Z&0-9]/, "").chars.to_a.join(".*")}.*/i
    end
  end
end
ActiveRecord::Base.include(FuzzyRecord)

<commit_msg>extend activesupport<commit_after>require "fuzzy_record/version"

module FuzzyRecord
  extend ActiveSupport::Concern
  module ClassMethods
    def fuzzy_search(args)
      if args.is_a? Hash
        search = args.map{|k,v| {k => generalize(v)}}.inject(:merge)
      else
        [:fuzzy_name, :ident, :name].each do |field|
          search = {field => args}
          break if self.respond_to?(field)
        end
      end
      self.select{ |record| search.map{|k,v| record.send(k) =~ v}.inject(:|)}
    end
    private
    def generalize(str)
      return /.*#{str.gsub(/[^a-zA-Z&0-9]/, "").chars.to_a.join(".*")}.*/i
    end
  end
end
ActiveRecord::Base.include(FuzzyRecord)


{'fraction_non_alphanumeric': 0.1635124905374716, 'fraction_numerical': 0.003028009084027252, 'mean_word_length': 2.7134831460674156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1635412', 'n_tokens_mistral': 487, 'n_tokens_neox': 465, 'n_words': 93}