Class: Pomo::List
- Inherits:
-
Object
- Object
- Pomo::List
- Defined in:
- lib/pomo/list.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
List path.
-
#tasks ⇒ Object
Task array.
Instance Method Summary collapse
-
#add(task) ⇒ Object
(also: #<<)
Add task to the list in memory (requires saving).
-
#initialize(path) ⇒ List
constructor
Initialize with path.
-
#load ⇒ Object
Load the list.
-
#save ⇒ Object
Save the list.
Constructor Details
#initialize(path) ⇒ List
Initialize with path.
18 19 20 21 22 |
# File 'lib/pomo/list.rb', line 18 def initialize path @path = File. path @tasks = [] load rescue save end |
Instance Attribute Details
#path ⇒ Object (readonly)
List path.
8 9 10 |
# File 'lib/pomo/list.rb', line 8 def path @path end |
#tasks ⇒ Object
Task array.
13 14 15 |
# File 'lib/pomo/list.rb', line 13 def tasks @tasks end |
Instance Method Details
#add(task) ⇒ Object Also known as: <<
Add task to the list in memory (requires saving).
27 28 29 |
# File 'lib/pomo/list.rb', line 27 def add task @tasks << task end |
#load ⇒ Object
Load the list.
45 46 47 48 |
# File 'lib/pomo/list.rb', line 45 def load @tasks = YAML.load_file path self end |
#save ⇒ Object
Save the list.
35 36 37 38 39 40 |
# File 'lib/pomo/list.rb', line 35 def save File.open(path, 'w') do |file| file.write YAML.dump(tasks) end self end |