Class: Nin::Todo
- Inherits:
-
Object
- Object
- Nin::Todo
- Defined in:
- lib/nin/todo.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #add(desc, date, tags) ⇒ Object
- #archive(*ids) ⇒ Object
- #complete(*ids) ⇒ Object
- #delete(*ids) ⇒ Object
- #delete_archived ⇒ Object
- #edit(id, desc, date, tags) ⇒ Object
-
#initialize(store = YamlStore.new, options = {}) ⇒ Todo
constructor
A new instance of Todo.
- #list ⇒ Object
Constructor Details
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/nin/todo.rb', line 3 def items @items end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/nin/todo.rb', line 4 def store @store end |
Instance Method Details
#add(desc, date, tags) ⇒ Object
22 23 24 25 |
# File 'lib/nin/todo.rb', line 22 def add(desc, date, ) @items << Item.new(next_id, desc, date, ) @store.write(to_hash) end |
#archive(*ids) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/nin/todo.rb', line 44 def archive(*ids) ids.each do |id| item = find_by_id(id.to_i) item.toggle_archived! end @store.write(to_hash) end |
#complete(*ids) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/nin/todo.rb', line 35 def complete(*ids) ids.each do |id| item = find_by_id(id.to_i) item.toggle_completed! end @store.write(to_hash) end |
#delete(*ids) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/nin/todo.rb', line 58 def delete(*ids) ids.each do |id| item = find_by_id(id.to_i) @items.delete(item) end reset_item_indices! end |
#delete_archived ⇒ Object
53 54 55 56 |
# File 'lib/nin/todo.rb', line 53 def delete_archived delete(*archived_items.map(&:id)) reset_item_indices! end |
#edit(id, desc, date, tags) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/nin/todo.rb', line 27 def edit(id, desc, date, ) item = find_by_id(id) item.desc = desc item.date = date item. = @store.write(to_hash) end |
#list ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/nin/todo.rb', line 12 def list if @options[:archived] @items else unarchived_items end.each do |item| puts item end end |