<commit_before>module AttributeBoolean

  VERSION = "0.0.1"

  module ClassMethods
    def attr_boolean(*args)
      options =
        if args.last.kind_of?(Hash)
          args.pop
        else
          {}
        end

      default_value =
        if options.has_key?(:default)
          !! options[:default]
        elsif options.has_key?("default")
          !! options["default"]
        else
          false
        end

      false_values =
        if options.has_key?(:false_values)
          options[:false_values]
        elsif options.has_key?("false_values")
          options["false_values"]
        end

      args.each do |name|
        ivar = "@#{ name }"

        define_method("#{ name }?") do
          value = instance_variable_get(ivar)

          if value == nil
            default_value
          else
            !! value
          end
        end

        define_method("#{ name }=") do |value|
          is_true =
            if value == nil
              default_value
            elsif false_values
              ! false_values.include?(value.to_s)
            else
              ! AttributeBoolean.false_values.include?(value.to_s)
            end

          instance_variable_set(ivar, is_true)
        end
      end
    end
  end

  def self.included(base)
    base.send(:extend, ClassMethods)
  end

  def self.reset_false_values!
    @false_values = [ false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'n', 'N', 'no', 'NO' ]
  end

  def self.false_values
    @false_values or reset_false_values!
  end

  def self.false_values=(false_values)
    @false_values = false_values
  end

  # Mix AttributeBoolean into ActiveRecord::Base if Rails is loaded.
  if defined? Rails::Railtie
    class Railtie < Rails::Railtie
      initializer "attribute_boolean.initialize" do
        ActiveSupport.on_load(:active_record) do
          ActiveRecord::Base.send(:include, AttributeBoolean)
        end
      end
    end
  end

end
<commit_msg>clean up class a little<commit_after>module AttributeBoolean

  VERSION = "0.0.1"

  module ClassMethods
    def attr_boolean(*args)
      options =
        if args.last.kind_of?(Hash)
          args.pop
        else
          {}
        end

      default_value =
        if options.has_key?(:default)
          !! options[:default]
        elsif options.has_key?("default")
          !! options["default"]
        else
          false
        end

      false_values =
        if options.has_key?(:false_values)
          options[:false_values]
        elsif options.has_key?("false_values")
          options["false_values"]
        end

      args.each do |name|
        ivar = "@#{ name }"

        define_method("#{ name }?") do
          value = instance_variable_get(ivar)

          if value == nil
            default_value
          else
            !! value
          end
        end

        define_method("#{ name }=") do |value|
          is_true =
            if value == nil
              default_value
            elsif false_values
              ! false_values.include?(value.to_s)
            else
              ! AttributeBoolean.false_values.include?(value.to_s)
            end

          instance_variable_set(ivar, is_true)
        end
      end
    end
  end

  class << self
    def included(base)
      base.send(:extend, ClassMethods)
    end

    def reset_false_values!
      @false_values = [ false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF', 'n', 'N', 'no', 'NO' ]
    end

    def false_values
      @false_values or reset_false_values!
    end

    def false_values=(false_values)
      @false_values = false_values
    end
  end

  # Mix AttributeBoolean into ActiveRecord::Base if Rails is loaded.
  if defined? Rails::Railtie
    class Railtie < Rails::Railtie
      initializer "attribute_boolean.initialize" do
        ActiveSupport.on_load(:active_record) do
          ActiveRecord::Base.send(:include, AttributeBoolean)
        end
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.09839357429718876, 'fraction_numerical': 0.0025100401606425703, 'mean_word_length': 1.8362989323843417, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7426966', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1156, 'n_words': 267}