class TodoTxt::List

Lists can be loaded from a file or instantiated in an empty state. They behave likes arrays and the can be written to a file when you're finished.

Attributes

tasks[R]

Public Class Methods

from_file(file) click to toggle source

Parses a Todo.txt formatted file @param [IO] file an IO input

# File lib/todotxt/list.rb, line 16
def self.from_file(file)
  tasks = file.readlines.map { |line|
    chomped = line.chomp
    Task.parse(chomped) unless chomped.empty?
  }.compact
  new tasks
end
new(tasks = []) click to toggle source

@param [Array<Task>] an array of tasks

# File lib/todotxt/list.rb, line 25
def initialize(tasks = [])
  @tasks = tasks
end

Public Instance Methods

each() { |t| ... } click to toggle source
# File lib/todotxt/list.rb, line 29
def each
  tasks.each { |t| yield t }
end
to_file(file) click to toggle source

Writes the list to a file @param [IO] file an IO object

# File lib/todotxt/list.rb, line 39
def to_file(file)
  file.write(to_s)
end
to_s() click to toggle source
# File lib/todotxt/list.rb, line 33
def to_s
  map(&:to_s).join("\n")
end