Class: Marsdawn::Source::FrontMatter

Inherits:
Object
  • Object
show all
Defined in:
lib/marsdawn/source/front_matter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attrObject (readonly)

Returns the value of attribute attr.



9
10
11
# File 'lib/marsdawn/source/front_matter.rb', line 9

def attr
  @attr
end

#contentObject (readonly)

Returns the value of attribute content.



9
10
11
# File 'lib/marsdawn/source/front_matter.rb', line 9

def content
  @content
end