Class: Pomo::List

Inherits:
Object
  • Object
show all
Defined in:
lib/pomo/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path path
  @tasks = []
  load rescue save
end

Instance Attribute Details

#pathObject (readonly)

List path.



8
9
10
# File 'lib/pomo/list.rb', line 8

def path
  @path
end

#tasksObject

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

#loadObject

Load the list.



45
46
47
48
# File 'lib/pomo/list.rb', line 45

def load
  @tasks = YAML.load_file path
  self
end

#saveObject

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