<commit_before>module Bulldog
  module Interpolation
    Error = Class.new(Bulldog::Error)

    def self.interpolate(template, record, name, style, overrides={})
      if overrides[:basename]
        overrides = overrides.dup
        extension = File.extname(overrides[:basename]).sub(/\A./, '')
        overrides[:extension] ||= extension
      end
      template.gsub(/:(?:(\w+)|\{(\w+?)\})/) do
        key = ($1 || $2).to_sym
        if (override = overrides[key])
          override
        elsif @interpolations.key?(key)
          @interpolations[key].call(record, name, style)
        else
          raise Error, "no such interpolation key: #{key}"
        end
      end
    end

    def self.to_interpolate(key, &substitution)
      @interpolations[key] = substitution<commit_msg>Duplicate the overrides hash less often when interpolating.<commit_after>module Bulldog
  module Interpolation
    Error = Class.new(Bulldog::Error)

    def self.interpolate(template, record, name, style, overrides={})
      if overrides[:basename] && overrides[:extension].nil?
        extension = File.extname(overrides[:basename]).sub(/\A./, '')
        overrides = overrides.merge(:extension => extension)
      end
      template.gsub(/:(?:(\w+)|\{(\w+?)\})/) do
        key = ($1 || $2).to_sym
        if (override = overrides[key])
          override
        elsif @interpolations.key?(key)
          @interpolations[key].call(record, name, style)
        else
          raise Error, "no such interpolation key: #{key}"
        end
      end
    end

    def self.to_interpolate(key, &substitution)
      @interpolations[key] = substitution
{'fraction_non_alphanumeric': 0.14233353695784973, 'fraction_numerical': 0.002443494196701283, 'mean_word_length': 2.648106904231626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2857613', 'n_tokens_mistral': 503, 'n_tokens_neox': 498, 'n_words': 108}