<commit_before>module RQRCode

  NUMERIC = ['0','1','2','3','4','5','6','7','8','9'].freeze

  class QRNumeric
    attr_reader :mode

    def initialize( data )
      @mode = QRMODE[:mode_number]

      raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)

      @data = data;
    end


    def get_length
      @data.size
    end

    def self.valid_data? data
      data.each_char do |s|
        return false if NUMERIC.index(s).nil?
      end
      true
    end


    def write( buffer)
      buffer.numeric_encoding_start(get_length)

      (@data.size).times do |i|
        if i % 3 == 0
          chars = @data[i]

          if @data[i + 1].present?
            chars << @data[i + 1]
          end

          if @data[i + 2].present?
            chars << @data[i + 2]
          end

          bit_length = get_bit_length(chars.length)
          buffer.put( get_code(chars), bit_length )
        end
      end
    end

    private

    NUMBER_LENGTH = {
      3 => 10,
      2 => 7,
      1 => 4
    }.freeze<commit_msg>present? is active support specific<commit_after>module RQRCode

  NUMERIC = ['0','1','2','3','4','5','6','7','8','9'].freeze

  class QRNumeric
    attr_reader :mode

    def initialize( data )
      @mode = QRMODE[:mode_number]

      raise QRCodeArgumentError, "Not a numeric string `#{data}`" unless QRNumeric.valid_data?(data)

      @data = data;
    end


    def get_length
      @data.size
    end

    def self.valid_data? data
      data.each_char do |s|
        return false if NUMERIC.index(s).nil?
      end
      true
    end


    def write( buffer)
      buffer.numeric_encoding_start(get_length)

      (@data.size).times do |i|
        if i % 3 == 0
          chars = @data[i]

          if @data[i + 1]
            chars << @data[i + 1]
          end

          if @data[i + 2]
            chars << @data[i + 2]
          end

          bit_length = get_bit_length(chars.length)
          buffer.put( get_code(chars), bit_length )
        end
      end
    end

    private

    NUMBER_LENGTH = {
      3 => 10,
      2 => 7,
      1 => 4
    }.freeze
{'fraction_non_alphanumeric': 0.12581852198316185, 'fraction_numerical': 0.021515434985968196, 'mean_word_length': 1.7743190661478598, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '1342436', 'n_tokens_mistral': 776, 'n_tokens_neox': 701, 'n_words': 175}