Class: Uniword::Generation::StructuredTextParser
- Inherits:
-
Object
- Object
- Uniword::Generation::StructuredTextParser
- Defined in:
- lib/uniword/generation/structured_text_parser.rb
Overview
Parses structured text files into content elements.
Supports two input formats:
-
YAML (.yml/.yaml): content array with element, text, style keys
-
Markdown (.md): heading levels, notes, examples via conventions
Returns an array of hashes, each with :element, :text, :style, and optional :children keys.
Class Method Summary collapse
-
.parse(input_path) ⇒ Array<Hash>
Parse a structured text file into content elements.
Class Method Details
.parse(input_path) ⇒ Array<Hash>
Parse a structured text file into content elements.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/uniword/generation/structured_text_parser.rb', line 27 def self.parse(input_path) validate_path(input_path) ext = File.extname(input_path).downcase content = File.read(input_path, encoding: "UTF-8") case ext when ".yml", ".yaml" parse_yaml(content) when ".md" parse_markdown(content) else raise ArgumentError, "Unsupported format: #{ext}. Use .yml, .yaml, or .md" end end |