Class: Rubdo::List
- Inherits:
-
Object
- Object
- Rubdo::List
- Defined in:
- lib/rubdo/list.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#todo_file ⇒ Object
readonly
Returns the value of attribute todo_file.
Class Method Summary collapse
Instance Method Summary collapse
- #add(description) ⇒ Object (also: #<<)
- #done(id) ⇒ Object
- #edit(id) ⇒ Object
-
#initialize(options) ⇒ List
constructor
A new instance of List.
- #to_a ⇒ Object
- #write ⇒ Object (also: #save)
Constructor Details
#initialize(options) ⇒ List
Returns a new instance of List.
15 16 17 18 |
# File 'lib/rubdo/list.rb', line 15 def initialize() @items = .fetch(:items) { [] } @todo_file = .fetch(:todo_file) { File.("~/.tasks/Todo.yml") } end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/rubdo/list.rb', line 7 def items @items end |
#todo_file ⇒ Object (readonly)
Returns the value of attribute todo_file.
7 8 9 |
# File 'lib/rubdo/list.rb', line 7 def todo_file @todo_file end |
Class Method Details
.read(file = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/rubdo/list.rb', line 9 def self.read(file = nil) todo_file = File.(file) items = File.exists?(todo_file) ? YAML.load_file(todo_file) : [] { items: items, todo_file: todo_file } end |
Instance Method Details
#add(description) ⇒ Object Also known as: <<
20 21 22 |
# File 'lib/rubdo/list.rb', line 20 def add(description) items << Item.new(description) end |
#done(id) ⇒ Object
25 26 27 |
# File 'lib/rubdo/list.rb', line 25 def done(id) items.delete_at id end |
#edit(id) ⇒ Object
29 30 31 |
# File 'lib/rubdo/list.rb', line 29 def edit(id) items[id] end |
#to_a ⇒ Object
38 39 40 |
# File 'lib/rubdo/list.rb', line 38 def to_a items end |
#write ⇒ Object Also known as: save
33 34 35 |
# File 'lib/rubdo/list.rb', line 33 def write File.open(todo_file, 'w') { |f| f.write(items.to_yaml) } end |