Skip to content

Instantly share code, notes, and snippets.

@BrianJoyce
Created October 16, 2012 03:43
Show Gist options
  • Save BrianJoyce/3897128 to your computer and use it in GitHub Desktop.
Save BrianJoyce/3897128 to your computer and use it in GitHub Desktop.
todo 1.9
require_relative 'todoList'
my_new_todo = Todo.new("some interesting stuff")
top_to_do = Todo.new("This at the top")
todo_list = TodoList.new
# todo_list.list
puts "ID | Date | Item | Priority | Completed | Tags |"
puts "--------------------------------------------------------------------------------------------------------------------"
# todo_list.append(my_new_todo.todo)
# todo_list.prepend(top_to_do.todo)
# puts
# todo_list.completed(4, "yes")
# puts
# todo_list.list
# puts
# todo_list.tag(2,"#will #you #work this")
todo_list.list("this")
# todo_list.open
# todo_list.save
#
# my_todo = Todo.new("this is a test")
# puts my_todo.inspect
#
# my_todo2 = Todo.new("this is a test too")
# puts my_todo2.inspect
# id | date | item | priority | completed | tags |
class Todo
attr_accessor :todo
def initialize(todo)
@todo = {}
# todo_id
date_time(Time.now.strftime("%m/%d/%Y"))
item(todo)
priority
complete?
tags
end
def complete?(complete="")
@todo[:complete] = complete
end
def priority(high_med_low="")
@todo[:priority] = high_med_low
end
def tags(tag="")
@todo[:tags] = []
end
def item(text)
@todo[:todo] = text
end
def date_time(time=Time.now)
@todo[:time] = time
end
end
require_relative 'todo'
class TodoList
attr_accessor :todo_list
def initialize
@todo_list = []
open
end
def list(tag='')
@todo_list.each_with_index do |task, n|
puts justify((n+1).to_s, 4) + \
justify(task[:time],12) + \
justify(task[:todo],40) + \
justify(task[:priority],9) + \
justify(task[:complete],10) + \
justify(task[:tags],30) if task[:tags].include?(tag)
end
save
end
def priority(num = 0, element)
@todo_list[num-1][:priority] = element if num > 0
save
end
def completed(num, element)
@todo_list[num-1][:complete] = element
save
end
def tag(num, element)
@todo_list[num-1][:tags] += element + " "
save
end
def justify(element, num)
element.nil? == false ? element.ljust(num) + "| " : " ".ljust(num) + "| "
end
def delete(num)
@todo_list.delete_at(num-1)
save
end
def append(task)
@todo_list << task
save
end
def prepend(task)
@todo_list.insert(0, task)
save
end
def open
todo_file = File.open("task_list.txt", "r")
todo_file.each_line {|task| @todo_list << eval(task) } if todo_file.nil? == false
end
def save
my_file = File.open("task_list.txt", "w")
my_file.puts @todo_list
my_file.close
end
end
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"", :complete=>"", :tags=>""}
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"", :complete=>"", :tags=>"#will #you #work #will #you #work #will #you #work #will #you #work #will #you #work #will #you #work #will #you #work #will #you #work #will #you #work this #will #you #work this "}
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"", :complete=>"", :tags=>""}
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"", :complete=>"yes", :tags=>""}
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"medium", :complete=>"yes", :tags=>"this is a tagthis is a tagthis is a tagthis is a tagthis is a tag "}
{:time=>"10/15/2012", :todo=>"This at the top", :priority=>"", :complete=>"", :tags=>""}
{:time=>"10/15/2012", :todo=>"some interesting stuff", :priority=>"", :complete=>"", :tags=>""}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment