<commit_before>class Http2::PostDataGenerator
  def initialize(pdata, args = {})
    @pdata, @args = pdata, args
  end

  def generate
    praw = ""

    if @pdata.is_a?(Hash)
      praw << generate_for_hash(@pdata)
    elsif @pdata.is_a?(Array)
      praw << generate_for_array(@pdata)
    else
      return @pdata.to_s
    end

    return praw
  end

  def generate_for_hash(hash)
    praw = ""

    @pdata.each do |key, val|
      praw << "&" if praw != ""

      key = "#{@args[:orig_key]}[#{key}]" if @args[:orig_key]

      if val.is_a?(Hash) || val.is_a?(Array)
        praw << ::Http2::PostDataGenerator.new(val, :orig_key => key).generate
      else
        data = ::Http2::PostDataGenerator.new(val).generate
        praw << "#{Http2::Utils.urlenc(key)}=#{Http2::Utils.urlenc(data)}"
      end
    end

    praw
  end

  def generate_for_array(array)
    praw = ""

    count = 0
    @pdata.each do |val|
      praw << "&" if praw != ""

      if @args[:orig_key]
        key = "#{@args[:orig_key]}[#{count}]"
      else
        key = count
      end

      if val.is_a?(Hash) || val.is_a?(Array)
        praw << ::Http2::PostDataGenerator.new(val, :orig_key => key).generate
      else
        data = ::Http2::PostDataGenerator.new(val).generate
        praw << "#{Http2::Utils.urlenc(key)}=#{Http2::Utils.urlenc(data)}"
      end

      count += 1
    end

    praw
  end
end<commit_msg>Extracted duplicate code out into method.<commit_after>class Http2::PostDataGenerator
  def initialize(pdata, args = {})
    @pdata, @args = pdata, args
  end

  def generate
    praw = ""

    if @pdata.is_a?(Hash)
      praw << generate_for_hash(@pdata)
    elsif @pdata.is_a?(Array)
      praw << generate_for_array(@pdata)
    else
      return @pdata.to_s
    end

    return praw
  end

private

  def generate_for_hash(hash)
    praw = ""

    @pdata.each do |key, val|
      praw << "&" if praw != ""
      key = "#{@args[:orig_key]}[#{key}]" if @args[:orig_key]
      praw << generate_key_value(key, val)
    end

    praw
  end

  def generate_for_array(array)
    praw = ""

    count = 0
    @pdata.each do |val|
      praw << "&" if praw != ""

      if @args[:orig_key]
        key = "#{@args[:orig_key]}[#{count}]"
      else
        key = count
      end

      praw << generate_key_value(key, val)
      count += 1
    end

    praw
  end

  def generate_key_value(key, value)
    if value.is_a?(Hash) || value.is_a?(Array)
      return ::Http2::PostDataGenerator.new(value, :orig_key => key).generate
    else
      data = ::Http2::PostDataGenerator.new(value).generate
      return "#{Http2::Utils.urlenc(key)}=#{Http2::Utils.urlenc(data)}"
    end
  end
end
{'fraction_non_alphanumeric': 0.15396113602391628, 'fraction_numerical': 0.006726457399103139, 'mean_word_length': 2.5177398160315376, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 6, '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': '7366405', 'n_tokens_mistral': 982, 'n_tokens_neox': 985, 'n_words': 194}