Class: Otterraft::Parser
- Inherits:
-
Object
- Object
- Otterraft::Parser
- Defined in:
- lib/otterraft/parser.rb
Constant Summary collapse
- FRONTMATTER_REGEX =
/^---\n(?<content>.+?)(?:\n---|\n\.\.\.)$/m.freeze
Instance Method Summary collapse
-
#initialize(text) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(text) ⇒ Parser
Returns a new instance of Parser.
9 10 11 |
# File 'lib/otterraft/parser.rb', line 9 def initialize(text) @text = text end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 |
# File 'lib/otterraft/parser.rb', line 13 def parse front_matter = @text.match(FRONTMATTER_REGEX) || raise("No front matter found") YAML.safe_load(front_matter[:content]) end |