Class: FrontMatterParser::SyntaxParser::SingleLineComment

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Factorizable

[]

Constructor Details

#initializeSingleLineComment

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

#regexpObject (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

.delimitersObject

:nocov:

Raises:

  • (NotImplementedError)

See Also:



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