Created
June 23, 2012 01:20
-
-
Save kmandreza/2976109 to your computer and use it in GitHub Desktop.
ToDoList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'docopt' | |
class Task | |
def initialize(contents) | |
end | |
end | |
class Todo | |
# attr_accessor :ToDo | |
# | |
def initialize | |
# @tasks = tasks | |
@filename = "untitled.txt" | |
@tasks = File.readlines(@filename) | |
end | |
def add(task) | |
write_file(@tasks << task) | |
end | |
def prepend(task) | |
write_file(@tasks.insert(0,task)) | |
end | |
# | |
def delete(number) | |
@tasks.delete_at(number.to_i - 1) | |
write_file(@tasks) | |
end | |
def write_file(tasks_array) | |
File.open(@filename, "w").puts(tasks_array) | |
end | |
end | |
todo = Todo.new | |
doc = "Usage... | |
-a add item Adds to the end | |
-p MESSAGE Adds to the beginning | |
-d NUM Deletes the line from the file | |
" | |
if __FILE__ == $0 | |
command = ARGV[0] | |
command_arg = ARGV[1] | |
options = Docopt(doc) | |
if command == "-a" | |
todo.add(command_arg) | |
# puts "we can add, yo" | |
elsif command == "-p" | |
todo.prepend(command_arg) | |
elsif command == "-d" | |
todo.delete(command_arg) | |
else | |
"nothing" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment