<commit_before>module Blurrily
  class MapGroup

    class << self
      attr_accessor :maps
    end

    @maps = {}

    def initialize(dir = '.')
      @dir = dir
    end

    def map(db)
      self.class.maps[db] ||= Map.new
    end

    def save
      self.class.maps.each do |db_name, map|
        map.save(File.join(@dir, db_name))
      end
    end
  end
end<commit_msg>[#46818783] loads the db if exists rather than creating new<commit_after>module Blurrily
  class MapGroup

    class << self
      attr_accessor :maps
    end

    @maps = {}

    def initialize(dir = '.')
      @dir = dir
    end

    def map(name)
      self.class.maps[name] ||= load_map(name) || Map.new
    end

    def save
      self.class.maps.each do |name, map|
        map.save(map_path(name))
      end
    end

    private

    def load_map(name)
      Map.load(map_path(name))
    rescue Errno::ENOENT
      nil
    end

    def map_path(name)
      File.join(@dir, "#{name}.dat")
    end
  end
end
{'fraction_non_alphanumeric': 0.11122345803842265, 'fraction_numerical': 0.008088978766430738, 'mean_word_length': 1.9909365558912386, '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': '4479727', 'n_tokens_mistral': 360, 'n_tokens_neox': 343, 'n_words': 85}