class FrontMatterParser::SyntaxParser::IndentationComment

Parser for syntaxes which use comments ended by indentation

Attributes

regexp[R]

@!attribute [r] regexp A regexp that returns two groups: front_matter and content

Public Class Methods

delimiters() click to toggle source

@see Factorizable :nocov:

# File lib/front_matter_parser/syntax_parser/indentation_comment.rb, line 24
def self.delimiters
  raise NotImplementedError
end
new() click to toggle source
# File lib/front_matter_parser/syntax_parser/indentation_comment.rb, line 13
def initialize
  @regexp = build_regexp(*self.class.delimiters)
end

Public Instance Methods

call(string) click to toggle source

@see SyntaxParser

# File lib/front_matter_parser/syntax_parser/indentation_comment.rb, line 18
def call(string)
  string.match(regexp)
end

Private Instance Methods

build_regexp(delimiter) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/front_matter_parser/syntax_parser/indentation_comment.rb, line 31
def build_regexp(delimiter)
  /
  \A
  [[:space:]]*
  (?<multiline_comment_indentation>^[[:blank:]]*)
  #{delimiter}
  [[:space:]]*
  ---
  (?<front_matter>.*?)
  ---
  [[:blank:]]*$[\n\r]
  (?<content>.*)
  \z
  /mx
end