<commit_before>module EY
  class EYRC
    attr_reader :path

    DEFAULT_PATH = "#{ENV['HOME']}/.eyrc"

    def self.load
      new(ENV['EYRC'] || DEFAULT_PATH)
    end

    def initialize(path)
      @path = Pathname.new(path).expand_path
    end

    def exist?
      path.exist?
    end

    def delete_api_token
      delete('api_token')
    end

    def api_token
      self['api_token']
    end

    def api_token=(token)
      self['api_token'] = token
    end

    private

    def [](key)
      read_data[key.to_s]
    end

    def []=(key,val)
      new_data = read_data.merge(key.to_s => val)
      write_data new_data
      val
    end

    def delete(key)
      data = read_data.dup
      res = data.delete(key)
      write_data data
      res
    end

    def read_data
      exist? && YAML.load(path.read) || {}
    end

    def write_data(new_data)
      path.open("w") {|f| YAML.dump(new_data, f) }
    end

  end
end
<commit_msg>Use ~ instead of ENV['HOME'] for .eyrc path.<commit_after>module EY
  class EYRC
    attr_reader :path

    DEFAULT_PATH = "~/.eyrc"

    def self.load
      new(ENV['EYRC'] || DEFAULT_PATH)
    end

    def initialize(path)
      @path = Pathname.new(path).expand_path
    end

    def exist?
      path.exist?
    end

    def delete_api_token
      delete('api_token')
    end

    def api_token
      self['api_token']
    end

    def api_token=(token)
      self['api_token'] = token
    end

    private

    def [](key)
      read_data[key.to_s]
    end

    def []=(key,val)
      new_data = read_data.merge(key.to_s => val)
      write_data new_data
      val
    end

    def delete(key)
      data = read_data.dup
      res = data.delete(key)
      write_data data
      res
    end

    def read_data
      exist? && YAML.load(path.read) || {}
    end

    def write_data(new_data)
      path.open("w") {|f| YAML.dump(new_data, f) }
    end

  end
end

{'fraction_non_alphanumeric': 0.11140167364016737, 'fraction_numerical': 0.0, 'mean_word_length': 1.9984326018808778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2094006', 'n_tokens_mistral': 713, 'n_tokens_neox': 681, 'n_words': 152}