Class: Todoloo::TaskList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/todoloo/task_list.rb

Defined Under Namespace

Classes: FoldedString

Constant Summary collapse

SEVERITY_INDEX =

Lower means higher priority

{
  "FIXME" => 100,
  "HACK" => 200,
  "TODO" => 300,
  "XXX" => 400,
  "NOTE" => 500,
  "HBD" => 600
}.freeze
UNKNOWN_INDEX =
1_000_000

Instance Method Summary collapse

Constructor Details

#initializeTaskList

Returns a new instance of TaskList.



19
20
21
# File 'lib/todoloo/task_list.rb', line 19

def initialize
  @tasks = []
end

Instance Method Details

#add(task) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/todoloo/task_list.rb', line 23

def add(task)
  if task.is_a?(Array)
    task.each { |t| add(t) }
  else
    raise ArgumentError, "Task type must be Todoloo::Task: #{task.inspect}" unless task.is_a?(Todoloo::Task)
    @tasks << task
  end

  self
end

#eachObject



34
35
36
37
38
# File 'lib/todoloo/task_list.rb', line 34

def each
  to_enum(:each) unless block_given?

  @tasks.each { |task| yield task }
end

#sortObject



40
41
42
43
44
45
46
# File 'lib/todoloo/task_list.rb', line 40

def sort
  @tasks.sort_by! do |t|
    [t.topics, task_severity(t), t.path, t.line, t.column]
  end

  self
end

#write(path, error: :raise) ⇒ Object

Structure:

TOPIC:
  TYPE:
    - description:
      path:


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/todoloo/task_list.rb', line 53

def write(path, error: :raise)
  output = YAML.dump(
    converted_tasks(
      error_handler: ErrorHandler.new(error)
    )
  )

  if path.is_a?(String)
    File.write(path, output)
  else
    path.write(output)
  end
end