Class: Mascot::Frontmatter
- Inherits:
-
Object
- Object
- Mascot::Frontmatter
- Defined in:
- lib/mascot.rb
Overview
Parses metadata from the header of the page.
Constant Summary collapse
- DELIMITER =
"---".freeze
- PATTERN =
/\A(#{DELIMITER}\n(.+)\n#{DELIMITER}\n)?(.+)\Z/m
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(content) ⇒ Frontmatter
constructor
A new instance of Frontmatter.
Constructor Details
#initialize(content) ⇒ Frontmatter
Returns a new instance of Frontmatter.
13 14 15 |
# File 'lib/mascot.rb', line 13 def initialize(content) _, @data, @body = content.match(PATTERN).captures end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/mascot.rb', line 11 def body @body end |
Instance Method Details
#data ⇒ Object
17 18 19 |
# File 'lib/mascot.rb', line 17 def data @data ? YAML.load(@data) : {} end |