Class: Phronomy::Loader::MarkdownLoader
- Defined in:
- lib/phronomy/loader/markdown_loader.rb
Overview
Loads a Markdown file, optionally splitting on top-level headings.
When +split_on_headings:+ is true (the default), each H1/H2 section becomes a separate document so that embeddings capture section semantics rather than the full file at once.
Constant Summary collapse
- HEADING_RE =
/^(\#{1,6})\s+(.+)$/
Instance Method Summary collapse
-
#initialize(split_on_headings: true) ⇒ MarkdownLoader
constructor
A new instance of MarkdownLoader.
- #load(source) ⇒ Array<Hash>
Constructor Details
#initialize(split_on_headings: true) ⇒ MarkdownLoader
Returns a new instance of MarkdownLoader.
27 28 29 |
# File 'lib/phronomy/loader/markdown_loader.rb', line 27 def initialize(split_on_headings: true) @split_on_headings = split_on_headings end |
Instance Method Details
#load(source) ⇒ Array<Hash>
34 35 36 37 38 39 |
# File 'lib/phronomy/loader/markdown_loader.rb', line 34 def load(source) content = File.read(source, encoding: "UTF-8") return [{text: content, metadata: {source: source}}] unless @split_on_headings split_by_headings(content, source) end |