Class: Aidp::Watch::PrdParser

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/watch/prd_parser.rb

Overview

Parses Gantt-oriented planning documents into a normalized task graph.

Defined Under Namespace

Classes: ParseError

Constant Summary collapse

SUPPORTED_FORMATS =
%i[mermaid ms_project_xml csv].freeze

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, format: nil) ⇒ PrdParser

Returns a new instance of PrdParser.



15
16
17
18
# File 'lib/aidp/watch/prd_parser.rb', line 15

def initialize(file_path:, format: nil)
  @file_path = file_path
  @format = normalize_format(format) || detect_format
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aidp/watch/prd_parser.rb', line 20

def parse
  raise ParseError, "File not found: #{@file_path}" unless File.exist?(@file_path)

  tasks = case @format
  when :mermaid then parse_mermaid(File.read(@file_path))
  when :ms_project_xml then parse_ms_project_xml(File.read(@file_path))
  when :csv then parse_csv
  else
    raise ParseError, "Unsupported format: #{@format}"
  end

  normalized_tasks = normalize_tasks(tasks)

  {
    format: @format,
    source_file: @file_path,
    tasks: normalized_tasks,
    metadata: (normalized_tasks)
  }
rescue REXML::ParseException => e
  raise ParseError, "Invalid XML: #{e.message}"
rescue CSV::MalformedCSVError => e
  raise ParseError, "Invalid CSV: #{e.message}"
end