Class: FrontMatterParser::SyntaxParser::SingleLineComment
- Inherits:
-
Object
- Object
- FrontMatterParser::SyntaxParser::SingleLineComment
- Extended by:
- Factorizable
- Defined in:
- lib/front_matter_parser/syntax_parser/single_line_comment.rb
Overview
Parser for syntaxes which each comment is for a single line
Instance Attribute Summary collapse
-
#regexp ⇒ Object
readonly
A regexp that returns two groups: front_matter (with comment delimiter in it) and content.
Class Method Summary collapse
-
.delimiters ⇒ Object
:nocov:.
Instance Method Summary collapse
- #call(string) ⇒ Object
-
#initialize ⇒ SingleLineComment
constructor
A new instance of SingleLineComment.
Methods included from Factorizable
Constructor Details
#initialize ⇒ SingleLineComment
Returns a new instance of SingleLineComment.
14 15 16 |
# File 'lib/front_matter_parser/syntax_parser/single_line_comment.rb', line 14 def initialize @regexp = build_regexp(*self.class.delimiters) end |
Instance Attribute Details
#regexp ⇒ Object (readonly)
A regexp that returns two groups: front_matter (with comment delimiter in it) and content
12 13 14 |
# File 'lib/front_matter_parser/syntax_parser/single_line_comment.rb', line 12 def regexp @regexp end |
Class Method Details
.delimiters ⇒ Object
:nocov:
34 35 36 |
# File 'lib/front_matter_parser/syntax_parser/single_line_comment.rb', line 34 def self.delimiters raise NotImplementedError end |
Instance Method Details
#call(string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |