<commit_before>module SmartFilterable
  extend ActiveSupport::Concern

  class_methods do
    def smart_filter(params)
      (params || {}).to_h.inject(all) do |results, (key, val)|
        results.smart_filter_key_val(key, val)
      end
    end

    def smart_filter_key_val(key, val)
      key = key.to_s
      col = columns_hash[key]
      case col.type
      when :string
        all.smart_filter_string(key, val)
      when :datetime
        all.smart_filter_datetime(key, val)
      when :integer
        all.smart_filter_enum(key, val) if key.in? defined_enums
      else
        Rails.logger.warn "Filtering column does not exist or invalid: #{key}"
      end
    end

    def smart_filter_string(key, val)
      all.where("#{key} LIKE ?", "%#{val}%")
    end

    def smart_filter_enum(key, val)
      all.where(key => self.defined_enums[key][val])
    end

    def smart_filter_datetime(key, val)
      day = case val
            when 'today', 'yesterday', 'tomorrow'
              Date.public_send(val)
            else
              Date.parse(val)
            end
      all.where(key => day.beginning_of_day..day.end_of_day)
    end
  end
end<commit_msg>remove useless self keyword<commit_after>module SmartFilterable
  extend ActiveSupport::Concern

  class_methods do
    def smart_filter(params)
      (params || {}).to_h.inject(all) do |results, (key, val)|
        results.smart_filter_key_val(key, val)
      end
    end

    def smart_filter_key_val(key, val)
      key = key.to_s
      col = columns_hash[key]
      case col.type
      when :string
        all.smart_filter_string(key, val)
      when :datetime
        all.smart_filter_datetime(key, val)
      when :integer
        all.smart_filter_enum(key, val) if key.in? defined_enums
      else
        Rails.logger.warn "Filtering column does not exist or invalid: #{key}"
      end
    end

    def smart_filter_string(key, val)
      all.where("#{key} LIKE ?", "%#{val}%")
    end

    def smart_filter_enum(key, val)
      all.where(key => defined_enums[key][val])
    end

    def smart_filter_datetime(key, val)
      day = case val
            when 'today', 'yesterday', 'tomorrow'
              Date.public_send(val)
            else
              Date.parse(val)
            end
      all.where(key => day.beginning_of_day..day.end_of_day)
    end
  end
end
{'fraction_non_alphanumeric': 0.10277185501066098, 'fraction_numerical': 0.0, 'mean_word_length': 2.3182461103253185, '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': '2124490', 'n_tokens_mistral': 772, 'n_tokens_neox': 755, 'n_words': 174}