Class: TodoTxt::List
- Inherits:
-
Object
- Object
- TodoTxt::List
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/todotxt/list.rb
Overview
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.
Class Method Summary collapse
-
.from_file(file) ⇒ Object
Parses a Todo.txt formatted file.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(tasks = []) ⇒ List
constructor
A new instance of List.
-
#to_file(file) ⇒ Object
Writes the list to a file.
- #to_s ⇒ Object
Constructor Details
#initialize(tasks = []) ⇒ List
Returns a new instance of List.
25 26 27 |
# File 'lib/todotxt/list.rb', line 25 def initialize(tasks = []) @tasks = tasks end |
Class Method Details
.from_file(file) ⇒ Object
Parses a Todo.txt formatted file
16 17 18 19 20 21 22 |
# 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 |
Instance Method Details
#each ⇒ Object
29 30 31 |
# File 'lib/todotxt/list.rb', line 29 def each tasks.each { |t| yield t } end |
#to_file(file) ⇒ Object
Writes the list to a file
39 40 41 |
# File 'lib/todotxt/list.rb', line 39 def to_file(file) file.write(to_s) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/todotxt/list.rb', line 33 def to_s map(&:to_s).join("\n") end |