<commit_before>module Atlas
  class GraphPersistor
    def initialize(dataset, path, export_modifier: nil)
      @dataset        = dataset
      @path           = path
      @export_modifier = export_modifier
    end

    def self.call(dataset, path, export_modifier: nil)
      new(dataset, path, export_modifier: export_modifier).persist!
    end

    def persist!
      data = EssentialExporter.dump(refinery_graph)
      @export_modifier.call(data) if @export_modifier
      File.open(@path, 'w') do |f|
        f.write data.to_yaml
      end
    end

    private

    def refinery_graph
      Runner.new(@dataset).refinery_graph(:export)
    end
  end
end
<commit_msg>Simplify GraphPersistor to a lambda<commit_after>module Atlas
    # Public: Builds the graph and exports it to a YAML file.
    #
    # dataset         - This dataset's graph will be built and persisted
    # path            - File to which the graph will be exported
    # export_modifier - Will be called on the graph's exported hash prior to saving it
    #
    # Returns a Hash
  GraphPersistor = lambda do |dataset, path, export_modifier: nil|
    data = EssentialExporter.dump(Runner.new(dataset).refinery_graph(:export))
    export_modifier.call(data) if export_modifier
    File.write(path, data.to_yaml)
    data
  end
end

{'fraction_non_alphanumeric': 0.07509578544061303, 'fraction_numerical': 0.0, 'mean_word_length': 2.818713450292398, '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': '5690253', 'n_tokens_mistral': 406, 'n_tokens_neox': 386, 'n_words': 116}