Class: MMToDo::ToDoList
- Inherits:
-
Object
- Object
- MMToDo::ToDoList
- Defined in:
- lib/mm_todo/todo_list.rb
Instance Method Summary collapse
- #add(todo = "") ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(save_file = "unnamed") ⇒ ToDoList
constructor
A new instance of ToDoList.
- #load ⇒ Object
- #mark_done(item) ⇒ Object
- #purge_done ⇒ Object
- #save ⇒ Object
- #select(index) ⇒ Object
- #show_all(dest = STDOUT) ⇒ Object
- #show_done(dest = STDOUT) ⇒ Object
- #show_todos(dest = STDOUT) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(save_file = "unnamed") ⇒ ToDoList
Returns a new instance of ToDoList.
7 8 9 10 11 12 |
# File 'lib/mm_todo/todo_list.rb', line 7 def initialize(save_file="unnamed") @list = [] @done = [] #@save_file = File.join(File.dirname(__FILE__), '\..\bin\\' + @save_file + '.save') @save_file = File.join(File.("../../bin/", File.dirname(__FILE__)), save_file + '.save') end |
Instance Method Details
#add(todo = "") ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/mm_todo/todo_list.rb', line 22 def add(todo = "") raise if todo =~ /^\s*$/ @list.push ToDoItem.new(todo, self) save rescue puts "[Empty todo not added...]" end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/mm_todo/todo_list.rb', line 34 def empty? return @list.empty? end |
#load ⇒ Object
18 19 20 |
# File 'lib/mm_todo/todo_list.rb', line 18 def load @list,@done = Marshal.load(File.read(@save_file)) end |
#mark_done(item) ⇒ Object
50 51 52 53 54 |
# File 'lib/mm_todo/todo_list.rb', line 50 def mark_done(item) @done.push item @list.delete item save end |
#purge_done ⇒ Object
66 67 68 69 |
# File 'lib/mm_todo/todo_list.rb', line 66 def purge_done @done = [] save end |
#save ⇒ Object
14 15 16 |
# File 'lib/mm_todo/todo_list.rb', line 14 def save File.open(@save_file, 'w') {|f| f.write Marshal.dump([@list,@done]) } end |
#select(index) ⇒ Object
46 47 48 |
# File 'lib/mm_todo/todo_list.rb', line 46 def select(index) return @list[index - 1] end |
#show_all(dest = STDOUT) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/mm_todo/todo_list.rb', line 56 def show_all(dest = STDOUT) puts "TODO:" puts "==========" show_todos puts "\n\nDone:" puts "==========" show_done puts "\n\n\n" end |
#show_done(dest = STDOUT) ⇒ Object
42 43 44 |
# File 'lib/mm_todo/todo_list.rb', line 42 def show_done(dest = STDOUT) @done.each {|item| dest.puts item} end |
#show_todos(dest = STDOUT) ⇒ Object
38 39 40 |
# File 'lib/mm_todo/todo_list.rb', line 38 def show_todos(dest = STDOUT) @list.each_index {|index| dest.puts "#{index + 1}. #{@list[index]}"} end |
#size ⇒ Object
30 31 32 |
# File 'lib/mm_todo/todo_list.rb', line 30 def size return @list.size end |