Class: Redpomo::TaskList

Inherits:
Array
  • Object
show all
Defined in:
lib/redpomo/task_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ TaskList

Returns a new instance of TaskList.



22
23
24
25
26
27
# File 'lib/redpomo/task_list.rb', line 22

def initialize(path)
  @path = path
  File.read(path).split("\n").each do |line|
    push Task.new(self, line)
  end
end

Class Method Details

.add!(task) ⇒ Object



17
18
19
20
# File 'lib/redpomo/task_list.rb', line 17

def self.add!(task)
  list = TaskList.new(Config.todo_path)
  list.add!(task)
end

.find(task_number) ⇒ Object



7
8
9
10
# File 'lib/redpomo/task_list.rb', line 7

def self.find(task_number)
  list = TaskList.new(Config.todo_path)
  list.find(task_number)
end

.pull_from_trackers!Object



12
13
14
15
# File 'lib/redpomo/task_list.rb', line 12

def self.pull_from_trackers!
  list = TaskList.new(Config.todo_path)
  list.pull_from_trackers!
end

Instance Method Details

#add!(task) ⇒ Object



38
39
40
41
# File 'lib/redpomo/task_list.rb', line 38

def add!(task)
  push task
  write!
end

#find(task_number) ⇒ Object



29
30
31
# File 'lib/redpomo/task_list.rb', line 29

def find(task_number)
  slice(task_number.to_i - 1)
end

#pull_from_trackers!Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/redpomo/task_list.rb', line 43

def pull_from_trackers!
  issue_tasks = Tracker.all.map(&:issues).flatten.map(&:to_task)
  delete_if do |task|
    task.tracker.present?
  end
  self << issue_tasks
  self.flatten!
  write!
  Redpomo.ui.info "Pulled #{issue_tasks.count} issues."
end

#remove!(task) ⇒ Object



33
34
35
36
# File 'lib/redpomo/task_list.rb', line 33

def remove!(task)
  delete(task)
  write!
end

#write!Object



54
55
56
57
58
# File 'lib/redpomo/task_list.rb', line 54

def write!
  File.open(@path, 'w') do |file|
    file.write map(&:orig).join("\n") + "\n"
  end
end