<commit_before>require 'time'
require 'yaml'

module Rubdo
  class List
    attr_reader :items, :completed, :storage, :archive

    def initialize
      @storage = File.expand_path('~/Dropbox/tasks/Todo.yml')
      @archive = File.expand_path('~/Dropbox/tasks/Archive.yml')
      @items, @completed = [], []
      @items = load @storage
      @completed = load @archive
    end

    def add(description)
      @items << Item.new(description)
    end

    def write
      File.open(@storage, 'w') { |todos| todos.write(@items.select { |item| item.done == false }.to_yaml) }
      File.open(@archive, 'w') { |todos| todos.write(@completed.to_yaml) }
    end

    def load(file)
      return YAML.load_file(file) if File.exists? file
      []
    end

    def done(id)
      abort("that id doesn't exists") if @items[id].nil?
      @items[id].done = true
      @items[id].completed_at = Time.new
      @completed << @items[id]
    end

    def info(id)
      @items[id].to_s
    end

    alias_method :<<, :add
  end
end<commit_msg>Created the save_directories if they don't exist<commit_after>require 'time'
require 'yaml'
require 'fileutils'

module Rubdo
  class List
    attr_reader :items, :completed, :storage, :archive

    def initialize
      @storage = File.expand_path('~/tasks/Todo.yml')
      @archive = File.expand_path('~/tasks/Archive.yml')
      @items, @completed = [], []
      @items = load @storage
      @completed = load @archive
      create_save_directory
    end

    def add(description)
      @items << Item.new(description)
    end

    def write
      File.open(@storage, 'w') { |todos| todos.write(@items.select { |item| item.done == false }.to_yaml) }
      File.open(@archive, 'w') { |todos| todos.write(@completed.to_yaml) }
    end

    def load(file)
      return YAML.load_file(file) if File.exists? file
      []
    end

    def done(id)
      abort("that id doesn't exists") if @items[id].nil?
      @items[id].done = true
      @items[id].completed_at = Time.new
      @completed << @items[id]
    end

    def info(id)
      @items[id].to_s
    end

    def create_save_directory
      FileUtils.mkdir File.dirname(@storage) unless File.exists? @storage
      FileUtils.mkdir File.dirname(@archive) unless File.exists? @archive
    end

    alias_method :<<, :add
  end
end
{'fraction_non_alphanumeric': 0.1371107266435986, 'fraction_numerical': 0.0, 'mean_word_length': 2.7548701298701297, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3346274', 'n_tokens_mistral': 795, 'n_tokens_neox': 752, 'n_words': 179}