Class: RubyFrontMatter::Parser
- Inherits:
-
Object
- Object
- RubyFrontMatter::Parser
- Defined in:
- lib/ruby_front_matter.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse(string = '') ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 |
# File 'lib/ruby_front_matter.rb', line 7 def initialize( = {}) = {delimiter: '---', parser: YAML}.merge() @delimiter = [:delimiter] @parser = [:parser] end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
5 6 7 |
# File 'lib/ruby_front_matter.rb', line 5 def parser @parser end |
Instance Method Details
#parse(string = '') ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ruby_front_matter.rb', line 13 def parse(string = '') res = [{},''] res[1] = string.lstrip.gsub(/#{@delimiter}(.*)#{@delimiter}/m) do |match| res[0] = @parser.load($~.captures.first.strip) '' end.strip res end |