Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created June 24, 2012 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmandreza/2985424 to your computer and use it in GitHub Desktop.
Save kmandreza/2985424 to your computer and use it in GitHub Desktop.
Refactored ToDo
doc = "Usage: example.rb [options] <arguments>...
Options:
-h --help show this help message and exit
add add task to the end of the list
prepend add task to the beginning of list"
require 'docopt'
if __FILE__ == $0
options = Docopt(doc, '1.0.0') # parse options based on doc above
end
command = ARGV[0]
task = ARGV[1..-1].join(" ")
if command == 'add'
File.new("list.todo", "w+") if !File.exists?("list.todo")
task_list = File.readlines("list.todo")
task_list << task
File.open("list.todo","w") do |f|
f.puts(task_list)
end
puts task_list
end
if command == 'prepend'
File.new("list.todo", "w+") if !File.exists?("list.todo")
task_list = File.readlines("list.todo")
task_list.unshift(task)
File.open("list.todo","w") do |f|
f.puts(task_list)
end
puts task_list
end
if command == 'delete'
File.new("list.todo", "w+") if !File.exists?("list.todo")
task_list = File.readlines("list.todo")
task_list.delete_at(task.to_i - 1)
File.open("list.todo","w") do |f|
f.puts(task_list)
end
puts task_list
end
if command == 'complete'
File.new("list.todo", "w+") if !File.exists?("list.todo")
task_list = File.readlines("list.todo")
task_list (task)
File.open("list.todo","w") do |f|
f.puts(task_list)
end
puts task_list
end
# To Do Item class
# create date
# complete date
# description
# identifier
# To Do List Class
# File Storage
#Command Line Parser
# To Do Item class
# create date
# complete date
# description (task)
# identifier
# To Do List Class
# File Storage
#Command Line Parser
# To Do Item class
# create date
# complete date
# description (task)
# identifier
# To Do List Class
# File Storage
#Command Line Parser
require 'digest/md5'
class TodoItem
def initialize(task, completed_time, creation_time)
@task = task
@completed_time = completed_time
@creation_time = creation_time
end
def iden
return Digest::MD5.hexdigest(@task)[-5..-1]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment