Class: Ernest::MetadataParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ernest/metadata_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ MetadataParser

Returns a new instance of MetadataParser.



9
10
11
12
# File 'lib/ernest/metadata_parser.rb', line 9

def initialize(text)
  @text = text
  @metadata = {}
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/ernest/metadata_parser.rb', line 7

def 
  @metadata
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/ernest/metadata_parser.rb', line 7

def text
  @text
end

Instance Method Details

#parseObject



14
15
16
17
18
19
20
# File 'lib/ernest/metadata_parser.rb', line 14

def parse
  if @text =~ /^(---\s*\n.*?\n?^---\s*$\n?)/m
    @metadata = YAML.load($1)
    @text.sub!($1, '')
  end
  Data.new(, text)
end