Class: Marsdawn::Source::FrontMatter
- Inherits:
-
Object
- Object
- Marsdawn::Source::FrontMatter
- Defined in:
- lib/marsdawn/source/front_matter.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#initialize(text) ⇒ FrontMatter
constructor
A new instance of FrontMatter.
Constructor Details
#initialize(text) ⇒ FrontMatter
Returns a new instance of FrontMatter.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/marsdawn/source/front_matter.rb', line 11 def initialize text m = text.match(/\A---*\n(?<attr>.*?)\n---*\n(?<content>.*)$/m) if m.nil? @attr = {} @content = text else @attr = Marsdawn::Util.hash_symbolize_keys_deep(YAML.load(m[:attr])) raise 'Invalid front-matter format.' unless @attr.kind_of?(Hash) @content = m[:content] end end |
Instance Attribute Details
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
9 10 11 |
# File 'lib/marsdawn/source/front_matter.rb', line 9 def attr @attr end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/marsdawn/source/front_matter.rb', line 9 def content @content end |