module TodoList
  class TaskList < Array

    SEPARATOR = " _;_ "

    def self.load(file_name)
      todolist = TaskList.new

      if File.exists?(file_name)
        File.foreach(file_name) do |line|
          description, done = line.chomp.split(SEPARATOR)

          todolist << Task.new(description, done.to_b)
        end
      end

      todolist
    end

    def save(file_name)
      File.open(file_name, "w") do |file|
        self.each { |e| file.puts("#{e.description}#{SEPARATOR}#{e.done?}") }
      end
    end

  end
end
