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, file_path) ⇒ 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, file_path) 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 |ls| Task.from_markdown ls end TaskList.new tasks, file_path end |
.from_markdown_file(file_path) ⇒ Object
20 21 22 23 |
# File 'lib/taskmeister/task_list_reader.rb', line 20 def self.from_markdown_file(file_path) lines = File.exist?(file_path) ? File.readlines(file_path) : [] self.from_markdown lines, file_path end |