<commit_before>module DataMapper
  class Property
    class Boolean < Object
      include PassThroughLoadDump

      primitive ::TrueClass

      def primitive?(value)
        value == true || value == false
      end

      # Typecast a value to a true or false
      #
      # @param [Integer, #to_str] value
      #   value to typecast
      #
      # @return [Boolean]
      #   true or false constructed from value
      #
      # @api private
      def typecast_to_primitive(value)
        if value.kind_of?(::Integer)
          return true  if value == 1
          return false if value == 0
        elsif value.respond_to?(:to_str)
          string_value = value.to_str.downcase
          return true  if %w[ true  1 t ].include?(string_value)
          return false if %w[ false 0 f ].include?(string_value)
        end

        value
      end
    end # class Boolean
  end # class Property
end # module DataMapper<commit_msg>Boolean#typecast refactor with a small perf improvement<commit_after>module DataMapper
  class Property
    class Boolean < Object
      include PassThroughLoadDump

      primitive ::TrueClass

      TRUE_VALUES  = [ 1, '1', 't', 'T', 'true',  'TRUE'  ].to_set.freeze
      FALSE_VALUES = [ 0, '0', 'f', 'F', 'false', 'FALSE' ].to_set.freeze

      def primitive?(value)
        value == true || value == false
      end

      # Typecast a value to a true or false
      #
      # @param [Integer, #to_str] value
      #   value to typecast
      #
      # @return [Boolean]
      #   true or false constructed from value
      #
      # @api private
      def typecast_to_primitive(value)
        if TRUE_VALUES.include?(value)
          true
        elsif FALSE_VALUES.include?(value)
          false
        else
          value
        end
      end
    end # class Boolean
  end # class Property
end # module DataMapper
{'fraction_non_alphanumeric': 0.08427267847557703, 'fraction_numerical': 0.0042941492216854536, 'mean_word_length': 1.9919743178170144, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2863019', 'n_tokens_mistral': 548, 'n_tokens_neox': 543, 'n_words': 174}