Module: Todo
- Defined in:
- lib/todo.rb,
lib/todo/version.rb,
lib/todo/controller.rb
Constant Summary collapse
Class Method Summary collapse
- .add_task(filename, notags, description, taskid = SecureRandom.hex(4), created_at = Time.now.to_s) ⇒ Object
- .del_task(filename, index) ⇒ Object
- .show_tasks(filename, tag) ⇒ Object
Class Method Details
.add_task(filename, notags, description, taskid = SecureRandom.hex(4), created_at = Time.now.to_s) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/todo/controller.rb', line 8 def self.add_task(filename,,description,taskid=SecureRandom.hex(4),created_at=Time.now.to_s) = [] _tasks = load_tasks(filename) = ask("(optional) Enter comma-separated tags: ", lambda {|s| s.split(/,\s*/) }) unless _tasks << { "taskid" => taskid, "created_at" => created_at, "description" => description, "tags" => } "<%= color('Task added', :green) %>" if(save_tasks(filename,_tasks)) end |
.del_task(filename, index) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/todo/controller.rb', line 23 def self.del_task(filename,index) _tasks=load_tasks(filename) if(_tasks.delete_at(index-1) && save_tasks(filename,_tasks)) "<%= color('Task deleted', :yellow) %>" else "<%= color('No task deleted', :red) %>" end end |
.show_tasks(filename, tag) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/todo/controller.rb', line 32 def self.show_tasks(filename,tag) _tasks=load_tasks(filename) _rtn = "Listing tasks (#{tag ? tag.to_s : 'all'})\n" _tasks.each_with_index do |task, i| next if(tag && !(task["tags"].include?(tag))) _rtn += "(#{i+1})\n" _rtn += "\t taskid : #{task['taskid']}\n" _rtn += "\t created_at : #{task['created_at']}\n" _rtn += "\t description : <%= color('"+task['description']+"', :yellow) %>\n" unless(task['tags'].empty?) _rtn += "\t tags : #{task['tags']}\n\n" end end _rtn end |