class FrontMatterParser::SyntaxParser::SingleLineComment
Parser for syntaxes which each comment is for a single line
Attributes
@!attribute [r] regexp A regexp that returns two groups: front_matter (with comment delimiter in it) and content
Public Class Methods
Source
# File lib/front_matter_parser/syntax_parser/single_line_comment.rb, line 34 def self.delimiters raise NotImplementedError end
@see Factorizable :nocov:
Source
# File lib/front_matter_parser/syntax_parser/single_line_comment.rb, line 14 def initialize @regexp = build_regexp(*self.class.delimiters) end
Source
# File lib/front_matter_parser/syntax_parser/single_line_comment.rb, line 39 def self.remove_delimiter(front_matter) delimiter = delimiters.first front_matter.gsub(/^[\s\t]*#{delimiter}/, '') end
@!visibility private
Public Instance Methods
Source
# File lib/front_matter_parser/syntax_parser/single_line_comment.rb, line 19 def call(string) match = string.match(regexp) if match front_matter = self.class.remove_delimiter(match[:front_matter]) { front_matter: front_matter, content: match[:content] } else match end end
@see SyntaxParser
Private Instance Methods
Source
# File lib/front_matter_parser/syntax_parser/single_line_comment.rb, line 47 def build_regexp(delimiter) / \A [[:space:]]* #{delimiter}[[:blank:]]* --- (?<front_matter>.*?) ^[[:blank:]]*#{delimiter}[[:blank:]]* --- [[:blank:]]*$[\n\r] (?<content>.*) \z /mx end
rubocop:disable Metrics/MethodLength