<commit_before>module Saxlsx
  class ColumnNameGenerator

    FIRST = 'A'
    LAST = 'Z'

    def self.next_to(previous)
      cache previous do
        parts = (previous || '').chars.to_a
        char = parts.pop

        if char.nil? || char.empty?
          FIRST
        elsif char < LAST
          parts << (char.ord + 1).chr
          parts.join
        else
          "#{next_to(parts.join)}A"
        end
      end
    end

    private

    def self.cache(key, &block)
      @cache ||= {}

      return @cache[key] if @cache.has_key? key

      @cache[key] = block.call
    end

  end
end<commit_msg>Simplify next column generator<commit_after>module Saxlsx
  class ColumnNameGenerator
    FIRST = 'A'
    LAST  = 'Z'

    def self.next_to(previous)
      char = previous ? previous[-1] : nil
      if char.nil?
        FIRST
      elsif char < LAST
        previous[0..-2] + (char.ord + 1).chr
      else
        "#{next_to(previous[0..-2])}A"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11428571428571428, 'fraction_numerical': 0.007142857142857143, 'mean_word_length': 1.7402234636871508, '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': '2745992', 'n_tokens_mistral': 344, 'n_tokens_neox': 322, 'n_words': 80}