<commit_before>require File.expand_path('../../horcrux', __FILE__)
require 'set'
require 'time'

module Horcrux
  module Entity
    def self.included(base)
      class << base
        attr_accessor :attributes, :writable_attributes, :default_attribute
      end

      base.attributes = Set.new
      base.writable_attributes = Set.new
      base.extend ClassMethods
    end

    module ClassMethods
      # Public
      def attr(type, *keys)
        method = "build_#{type}_attr"
        if respond_to?(method)
          send method, keys, false
        else
          raise TypeError, "Type #{type.inspect} not recognized."
        end
      end

      # Public
      def readonly(type, *keys)
        method = "build_#{type}_attr"
        if respond_to?(method)
          send method, keys, true
        else
          raise TypeError, "Type #{type.inspect} not recognized."
        end
      end

      # Public
      def from(hash = {})
        hash.respond_to?(@default_attribute) ? hash : new(hash)
      end

      def build_string_attr(keys, is_readonly)
        attr_reader *keys

        build_attrs(keys, is_readonly) do |key_s|
          ivar_key = "@#{key_s}"
          define_method "#{key_s}=" do |value|
            instance_variable_set ivar_key, value
          end
        end
      end

      def build_bool_attr(keys, is_readonly)
        attr_reader *keys

        build_attrs(keys, is_readonly) do |key_s|
          ivar_key = "@#{key_s}"

          define_method "#{key_s}?" do
            !!instance_variable_get(ivar_key)
          end

          define_method "#{key_s}=" do |value|
            instance_variable_set ivar_key, case value
              when Fixnum  then value > 0
              when /t|f/i  then value =~ /t/i ? true : false
              else !!value
            end
          end
        end
      end
<commit_msg>Use Integer instead of Fixnum<commit_after>require File.expand_path('../../horcrux', __FILE__)
require 'set'
require 'time'

module Horcrux
  module Entity
    def self.included(base)
      class << base
        attr_accessor :attributes, :writable_attributes, :default_attribute
      end

      base.attributes = Set.new
      base.writable_attributes = Set.new
      base.extend ClassMethods
    end

    module ClassMethods
      # Public
      def attr(type, *keys)
        method = "build_#{type}_attr"
        if respond_to?(method)
          send method, keys, false
        else
          raise TypeError, "Type #{type.inspect} not recognized."
        end
      end

      # Public
      def readonly(type, *keys)
        method = "build_#{type}_attr"
        if respond_to?(method)
          send method, keys, true
        else
          raise TypeError, "Type #{type.inspect} not recognized."
        end
      end

      # Public
      def from(hash = {})
        hash.respond_to?(@default_attribute) ? hash : new(hash)
      end

      def build_string_attr(keys, is_readonly)
        attr_reader *keys

        build_attrs(keys, is_readonly) do |key_s|
          ivar_key = "@#{key_s}"
          define_method "#{key_s}=" do |value|
            instance_variable_set ivar_key, value
          end
        end
      end

      def build_bool_attr(keys, is_readonly)
        attr_reader *keys

        build_attrs(keys, is_readonly) do |key_s|
          ivar_key = "@#{key_s}"

          define_method "#{key_s}?" do
            !!instance_variable_get(ivar_key)
          end

          define_method "#{key_s}=" do |value|
            instance_variable_set ivar_key, case value
              when Integer then value > 0
              when /t|f/i  then value =~ /t/i ? true : false
              else !!value
            end
          end
        end
      end

{'fraction_non_alphanumeric': 0.09154175588865096, 'fraction_numerical': 0.0005353319057815846, 'mean_word_length': 1.8483231707317074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1510583', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1101, 'n_words': 286}