Class: Taskmeister::TaskListReader
- Inherits:
-
Object
- Object
- Taskmeister::TaskListReader
- Defined in:
- lib/taskmeister/task_list_reader.rb
Class Method Summary collapse
Class Method Details
.from_markdown(file_lines) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/taskmeister/task_list_reader.rb', line 3 def self.from_markdown(file_lines) grouped_lines = \ file_lines.map(&:chomp) .reject(&:empty?) .reduce([]) do |acc, l| acc << [l] if l.match(/\A[^\s>]/) # A new task acc.last << l if l.match(/\A>/) # A line of note for the latest task acc end tasks = grouped_lines.map do |l| Task.from_markdown(l) end TaskList.new tasks end |
.from_markdown_file(path) ⇒ Object
20 21 22 23 |
# File 'lib/taskmeister/task_list_reader.rb', line 20 def self.from_markdown_file(path) lines = File.exist?(path) ? File.readlines(path) : [] from_markdown lines end |