<commit_before># encoding: utf-8
module EnumerateIt
  module ClassMethods
    def has_enumeration_for(attribute, options = {})
      self.enumerations = self.enumerations.dup

      define_enumeration_class attribute, options
      create_enumeration_humanize_method options[:with], attribute
      store_enumeration options[:with], attribute

      unless options[:skip_validation]
        set_validations attribute, options
      end

      if options[:create_helpers]
        create_helper_methods options[:with], attribute, options[:create_helpers]
        create_mutator_methods options[:with], attribute, options[:create_helpers]
        create_polymorphic_methods options[:with], attribute, options[:create_helpers]
      end

      if options[:create_scopes]
        create_scopes options[:with], attribute, options[:create_scopes]
      end
    end

    private

    def store_enumeration(klass, attribute)
      enumerations[attribute] = klass
    end

    def create_enumeration_humanize_method(klass, attribute_name)
      class_eval do
        define_method "#{attribute_name}_humanize" do
          values = klass.enumeration.values.detect { |v| v[0] == self.send(attribute_name) }

          values ? klass.translate(values[1]) : nil
        end
      end
    end

    def create_helper_methods(klass, attribute_name, helpers)
      prefix_name = "#{attribute_name}_" if helpers.is_a?(Hash) && helpers[:prefix]

      class_eval do
        klass.enumeration.keys.each do |option|
          define_method "#{prefix_name}#{option}?" do
            self.send(attribute_name) == klass.enumeration[option].first<commit_msg>Clean up code<commit_after># encoding: utf-8
module EnumerateIt
  module ClassMethods
    def has_enumeration_for(attribute, options = {})
      self.enumerations = self.enumerations.dup

      define_enumeration_class attribute, options
      create_enumeration_humanize_method options[:with], attribute
      store_enumeration options[:with], attribute

      unless options[:skip_validation]
        set_validations attribute, options
      end

      if options[:create_helpers]
        create_helper_methods options[:with],      attribute, options[:create_helpers]
        create_mutator_methods options[:with],     attribute, options[:create_helpers]
        create_polymorphic_methods options[:with], attribute, options[:create_helpers]
      end

      if options[:create_scopes]
        create_scopes options[:with], attribute, options[:create_scopes]
      end
    end

    private

    def store_enumeration(klass, attribute)
      enumerations[attribute] = klass
    end

    def create_enumeration_humanize_method(klass, attribute_name)
      class_eval do
        define_method "#{attribute_name}_humanize" do
          values = klass.enumeration.values.detect { |v| v[0] == self.send(attribute_name) }

          values ? klass.translate(values[1]) : nil
        end
      end
    end

    def create_helper_methods(klass, attribute_name, helpers)
      prefix_name = "#{attribute_name}_" if helpers.is_a?(Hash) && helpers[:prefix]

      class_eval do
        klass.enumeration.keys.each do |option|
          define_method "#{prefix_name}#{option}?" do
            self.send(attribute_name) == klass.enumeration[option].first
{'fraction_non_alphanumeric': 0.08854961832061069, 'fraction_numerical': 0.00183206106870229, 'mean_word_length': 3.4390243902439024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '226211', 'n_tokens_mistral': 929, 'n_tokens_neox': 920, 'n_words': 191}