<commit_before>class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler

  ALLOWED_TRACKER_OPTIONS = [:cookie_domain, :user_id]

  class Send < OpenStruct
    def initialize(attrs = {})
      attrs.reverse_merge!(type: 'event')
      super
    end

    def write
      ['send', event].to_json.gsub(/\[|\]/, '')
    end

    def event
      { hitType: self.type }.merge(attributes.stringify_values).compact
    end

    def attributes
      Hash[to_h.slice(:category, :action, :label, :value).map { |k,v| [self.type.to_s + k.to_s.capitalize, v] }]
    end
  end

  class Ecommerce < OpenStruct
    def write
      ["ecommerce:#{self.type}", self.to_h.except(:type).compact.stringify_values].to_json.gsub(/\[|\]/, '')
    end
  end

  def tracker
    options[:tracker].respond_to?(:call) ? options[:tracker].call(env) : options[:tracker]
  end

  def tracker_options
    @tracker_options ||= {}.tap do |tracker_options|
      options.slice(*ALLOWED_TRACKER_OPTIONS).each do |key, value|
        if option_value = value.respond_to?(:call) ? value.call(env) : value
          tracker_options["#{key}".camelize(:lower).to_sym] = "#{option_value}"
        end
      end
    end
  end
<commit_msg>replace string interpolation with to_s<commit_after>class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler

  ALLOWED_TRACKER_OPTIONS = [:cookie_domain, :user_id]

  class Send < OpenStruct
    def initialize(attrs = {})
      attrs.reverse_merge!(type: 'event')
      super
    end

    def write
      ['send', event].to_json.gsub(/\[|\]/, '')
    end

    def event
      { hitType: self.type }.merge(attributes.stringify_values).compact
    end

    def attributes
      Hash[to_h.slice(:category, :action, :label, :value).map { |k,v| [self.type.to_s + k.to_s.capitalize, v] }]
    end
  end

  class Ecommerce < OpenStruct
    def write
      ["ecommerce:#{self.type}", self.to_h.except(:type).compact.stringify_values].to_json.gsub(/\[|\]/, '')
    end
  end

  def tracker
    options[:tracker].respond_to?(:call) ? options[:tracker].call(env) : options[:tracker]
  end

  def tracker_options
    @tracker_options ||= {}.tap do |tracker_options|
      options.slice(*ALLOWED_TRACKER_OPTIONS).each do |key, value|
        if option_value = value.respond_to?(:call) ? value.call(env) : value
          tracker_options[key.to_s.camelize(:lower).to_sym] = option_value.to_s
        end
      end
    end
  end

{'fraction_non_alphanumeric': 0.1474120082815735, 'fraction_numerical': 0.0, 'mean_word_length': 3.231173380035026, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7553741', 'n_tokens_mistral': 851, 'n_tokens_neox': 820, 'n_words': 152}