Class: Otterraft::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/otterraft/parser.rb

Constant Summary collapse

FRONTMATTER_REGEX =
/^---\n(?<content>.+?)(?:\n---|\n\.\.\.)$/m.freeze

Instance Method Summary collapse

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

#parseObject



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