<commit_before>require 'csv'

module Julia
  class Builder
    attr_reader :collection, :csv_options

    def initialize(collection, csv_options = Hash.new)
      @collection, @csv_options = collection, default_options.merge(csv_options)
    end

    def default_options
      {
        headers: columns_config.keys,
        write_headers: true
      }
    end

    def self.column(keyname, action = nil, &block)
      columns_config[keyname] = Action.new(keyname, action, &block)
    end

    def self.columns(*args)
      args.each do |key|
        column(key)
      end
    end

    def self.columns_config
      @columns_config ||= {}
    end

    def build
      CSV.generate(csv_options) do |csv|
        collection.each do |record|
          csv << columns_config.values.map do |action|
            action.get_value(record, self)
          end
        end
      end
    end

    def self.build(collection, csv_options = Hash.new)
      new(collection, csv_options).build
    end

    protected

    def columns_config
      self.class.columns_config
    end
  end
end
<commit_msg>fix for ruby 3 (#13)<commit_after>require 'csv'

module Julia
  class Builder
    attr_reader :collection, :csv_options

    def initialize(collection, csv_options = Hash.new)
      @collection, @csv_options = collection, default_options.merge(csv_options)
    end

    def default_options
      {
        headers: columns_config.keys,
        write_headers: true
      }
    end

    def self.column(keyname, action = nil, &block)
      columns_config[keyname] = Action.new(keyname, action, &block)
    end

    def self.columns(*args)
      args.each do |key|
        column(key)
      end
    end

    def self.columns_config
      @columns_config ||= {}
    end

    def build
      CSV.generate(**csv_options) do |csv|
        collection.each do |record|
          csv << columns_config.values.map do |action|
            action.get_value(record, self)
          end
        end
      end
    end

    def self.build(collection, csv_options = Hash.new)
      new(collection, csv_options).build
    end

    protected

    def columns_config
      self.class.columns_config
    end
  end
end

{'fraction_non_alphanumeric': 0.08382959230416857, 'fraction_numerical': 0.001374255611543747, 'mean_word_length': 2.2743628185907045, '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': '4584997', 'n_tokens_mistral': 680, 'n_tokens_neox': 653, 'n_words': 162}