<commit_before>require 'csv'

class CSVTransform
  def initialize(*attributes)
    @attributes = attributes
  end

  def call(user_list)
    user_list.
      # map to array of attributes
      map { |u| row_for(u) }.
      # prepend the header row
      unshift(headers).
      # turn each row into csv data
      map { |row| row.to_csv }.
      # join the rows into one blob
      join
  end

  def row_for(user)
    @attributes.map { |attr| user.public_send(attr) }
  end

  def headers
    @attributes.map { |attr| attr.to_s.sub('_', ' ') }
  end
end<commit_msg>Clean up comments<commit_after>require 'csv'

class CSVTransform
  def initialize(*attributes)
    @attributes = attributes
  end

  def call(user_list)
    user_list.
      map { |user| row_for(user) }. # map to array of attributes
      unshift(headers).             # prepend the header row
      map { |row| row.to_csv }.     # turn each row into csv data
      join                          # join the rows into one blob
  end

  def row_for(user)
    @attributes.map { |attr| user.public_send(attr) }
  end

  def headers
    @attributes.map { |attr| attr.to_s.sub('_', ' ') }
  end
end
{'fraction_non_alphanumeric': 0.10198789974070872, 'fraction_numerical': 0.0, 'mean_word_length': 2.346820809248555, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3256380', 'n_tokens_mistral': 383, 'n_tokens_neox': 372, 'n_words': 111}