Created
October 19, 2012 22:45
-
-
Save BrianJoyce/3921156 to your computer and use it in GitHub Desktop.
todo_2
This file contains hidden or 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 'yaml' | |
| require_relative 'todo_item_yaml.rb' | |
| my_new_todo = Todo.new("ZZZZZZZZND") | |
| top_to_do = Todo.new("This at the top") | |
| todo_list = TodoList.new | |
| input = ARGV | |
| # puts input | |
| search_item = "#will" | |
| search_field = '' | |
| input.each {|tag| tags += tag if tag.start_with?('#')} | |
| puts tags | |
| puts "ID | Date | Item | Priority | Completed | Tags |" | |
| puts "--------------------------------------------------------------------------------------------------------------------" | |
| # todo_list.tag(2,"#will #you #work this") | |
| # todo_list.append(my_new_todo.todo) | |
| # todo_list.append(my_new_todo.todo) | |
| # todo_list.prepend(top_to_do.todo) | |
| todo_list.tag(12,"#will #you #work") | |
| # todo_list.sortby(:priority) | |
| # todo_list.filter(:tags, tags.split(" ")) | |
| # todo_list.completed(5, "yes") | |
| todo_list.priority(4, "high") | |
| # todo_list.delete(4) | |
| # puts | |
| # todo_list.completed(4, "yes") | |
| # puts | |
| # todo_list.list | |
| # puts | |
| # 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 | |
| todo_list.list |
This file contains hidden or 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
| class Todo | |
| attr_accessor :todo, :date_time, :item, :complete, :priority, :tags | |
| def initialize(todo) | |
| @todo = {} | |
| # todo_id | |
| @todo[:time] = Time.now.strftime("%m/%d/%Y") | |
| @todo[:item] = todo | |
| @todo[:priority] = "" | |
| @todo[:complete] = "" | |
| @todo[:tags] = "" | |
| end | |
| end |
This file contains hidden or 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_relative 'todo' | |
| class Printer | |
| def self.list(todo_list) | |
| todo_list.each_with_index do |task, n| | |
| puts justify((n+1).to_s, 4) + \ | |
| justify(task[:time],12) + \ | |
| justify(task[:item],40) + \ | |
| justify(task[:priority],9) + \ | |
| justify(task[:complete],10) + \ | |
| justify(task[:tags],30) | |
| end | |
| end | |
| def self.justify(element, num) | |
| element.nil? == false ? element.ljust(num) + "| " : " ".ljust(num) + "| " | |
| end | |
| end | |
| class FileInterface | |
| def initialize(filename = 'task_list.yml') | |
| @filename = filename | |
| end | |
| def open | |
| YAML::load(File.read(@filename)) | |
| end | |
| end | |
| class TodoList | |
| attr_accessor :todo_list | |
| def initialize | |
| @todo_list = FileInterface.new.open | |
| end | |
| def priority(num = 0, element) | |
| save_after{@todo_list[num-1][:priority] = element if num > 0} | |
| end | |
| def completed(num, element) | |
| save_after{@todo_list[num-1][:complete] = element} | |
| end | |
| def tag(num, element) | |
| save_after{@todo_list[num-1][:tags] += element + " "} | |
| end | |
| def delete(num) | |
| save_after{@todo_list.delete_at(num-1)} | |
| end | |
| def append(task) | |
| save_after{@todo_list << task} | |
| end | |
| def prepend(task) | |
| save_after{@todo_list.insert(0, task)} | |
| end | |
| def filter(f_field, filter_item) | |
| save_after{Printer.list(@todo_list.select {|task| (task[f_field.to_sym].split(" ") & filter_item).empty? == false})} | |
| end | |
| def sortby(sort_field) | |
| save_after{Printer.list(@todo_list.sort_by {|task| task[sort_field]})} | |
| end | |
| def list | |
| Printer.list(@todo_list) | |
| end | |
| def save_after(&b) | |
| yield | |
| my_file = File.open('task_list.yml', "w") | |
| my_file.write @todo_list.to_yaml | |
| my_file.close | |
| end | |
| end |
This file contains hidden or 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 'pry' | |
| require_relative 'todo' | |
| class Printer | |
| def self.list(todo_list) | |
| todo_list.each_with_index do |task, n| | |
| puts justify((n+1).to_s, 4) + \ | |
| justify(task[:time],12) + \ | |
| justify(task[:item],40) + \ | |
| justify(task[:priority],9) + \ | |
| justify(task[:complete],10) + \ | |
| justify(task[:tags],30) | |
| end | |
| end | |
| def self.justify(element, num) | |
| element.nil? == false ? element.ljust(num) + "| " : " ".ljust(num) + "| " | |
| end | |
| end | |
| class FileInterface | |
| def initialize(filename = 'task_list.yml') | |
| @filename = filename | |
| end | |
| # | |
| # def open | |
| # todo_list = [] | |
| # todo_file = File.open(@filename, "r") | |
| # todo_file.each_line {|task| todo_list << eval(task)} if todo_file.nil? == false | |
| # todo_list | |
| # end | |
| # | |
| # require 'yaml' | |
| # log = File.open( "/var/log/apache.yaml" ) | |
| # yp = YAML::load_documents( log ) { |doc| | |
| # puts "#{doc['at']} #{doc['type']} #{doc['url']}" | |
| # } | |
| # | |
| def open | |
| todo_list = [] | |
| todo_file = File.open(@filename) | |
| # todo_file.each_line {|task| todo_list << eval(task)} if todo_file.nil? == false | |
| todo_list = YAML::load_documents( todo_file ) | |
| todo_list | |
| end | |
| end | |
| class TodoList | |
| attr_accessor :todo_list | |
| def initialize | |
| @todo_list = FileInterface.new.open | |
| end | |
| def priority(num = 0, element) | |
| save_after{@todo_list[num-1][:priority] = element if num > 0} | |
| end | |
| def completed(num, element) | |
| save_after{@todo_list[num-1][:complete] = element} | |
| end | |
| def tag(num, element) | |
| save_after{@todo_list[num-1][:tags] += element + " "} | |
| end | |
| def delete(num) | |
| save_after{@todo_list.delete_at(num-1)} | |
| end | |
| def append(task) | |
| save_after{@todo_list << task} | |
| end | |
| def prepend(task) | |
| save_after{@todo_list.insert(0, task)} | |
| end | |
| def filter(f_field, filter_item) | |
| save_after{Printer.list(@todo_list.select {|task| (task[f_field.to_sym].split(" ") & filter_item).empty? == false})} | |
| end | |
| def sortby(sort_field) | |
| save_after{Printer.list(@todo_list.sort_by {|task| task[sort_field]})} | |
| end | |
| def list | |
| Printer.list(@todo_list) | |
| end | |
| # def save_after(&b) | |
| # yield | |
| # my_file = File.open('task_list.txt', "w") | |
| # my_file.puts @todo_list | |
| # my_file.close | |
| # end | |
| def save_after(&b) | |
| yield | |
| # File.open(Dir.pwd + PATH, 'w+') {|f| f.write(options_hash.to_yaml) } | |
| my_file = File.open('task_list.yml', "w") | |
| my_file.write @todo_list.to_yaml | |
| my_file.close | |
| end | |
| end |
This file contains hidden or 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 'yaml' | |
| def open | |
| todo_list = [] | |
| todo_file = File.open('task_list.yml') | |
| # yp = YAML::load_documents( log ) | |
| todo_list = YAML::load_documents( todo_file ) | |
| # todo_file.each_line {|task| todo_list << eval(task)} if todo_file.nil? == false | |
| todo_list | |
| end | |
| p open |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment