Class: Aidp::Planning::Parsers::DocumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/planning/parsers/document_parser.rb

Overview

Parses existing documentation files to extract structured information Uses Zero Framework Cognition (ZFC) for semantic analysis

Instance Method Summary collapse

Constructor Details

#initialize(ai_decision_engine: nil) ⇒ DocumentParser

Returns a new instance of DocumentParser.



11
12
13
# File 'lib/aidp/planning/parsers/document_parser.rb', line 11

def initialize(ai_decision_engine: nil)
  @ai_decision_engine = ai_decision_engine
end

Instance Method Details

#parse_directory(dir_path) ⇒ Array<Hash>

Parse all markdown files in a directory

Parameters:

  • dir_path (String)

    Directory path

Returns:

  • (Array<Hash>)

    Array of parsed documents



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/aidp/planning/parsers/document_parser.rb', line 40

def parse_directory(dir_path)
  Aidp.log_debug("document_parser", "parse_directory", path: dir_path)

  unless Dir.exist?(dir_path)
    Aidp.log_error("document_parser", "directory_not_found", path: dir_path)
    raise ArgumentError, "Directory not found: #{dir_path}"
  end

  markdown_files = Dir.glob(File.join(dir_path, "**", "*.md"))
  Aidp.log_debug("document_parser", "found_files", count: markdown_files.size)

  markdown_files.map { |file| parse_file(file) }
end

#parse_file(file_path) ⇒ Hash

Parse a single file and detect its structure

Parameters:

  • file_path (String)

    Path to the markdown file

Returns:

  • (Hash)

    Parsed document with type and sections



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aidp/planning/parsers/document_parser.rb', line 18

def parse_file(file_path)
  Aidp.log_debug("document_parser", "parse_file", path: file_path)

  unless File.exist?(file_path)
    Aidp.log_error("document_parser", "file_not_found", path: file_path)
    raise ArgumentError, "File not found: #{file_path}"
  end

  content = File.read(file_path)
  Aidp.log_debug("document_parser", "read_content", size: content.length)

  {
    path: file_path,
    type: detect_document_type(content),
    sections: extract_sections(content),
    raw_content: content
  }
end