class RubyMatter::Stringifier
Stringifies data
, content
and optional excerpt
, based on the arguments supplied to the initializer.
Public Class Methods
new( content, data: {}, delimiters:, language: nil, engines: {}, excerpt: nil, excerpt_separator: nil )
click to toggle source
Instantiate the stringifier. This should not need to be called directly, as the RubyMatter
module methods will handle this. For more information, see the following method that instantiates a stringifier:
-
RubyMatter.stringify
- stringifydata
,content
and optionalexcerpt
.
Returns¶ ↑
- (
RubyMatter::Stringifier
) -
An instance of the stringifier.
# File lib/ruby_matter/stringifier.rb, line 19 def initialize( content, data: {}, delimiters:, language: nil, engines: {}, excerpt: nil, excerpt_separator: nil ) @content = content @data = data @delimiters = delimiters @language = language @engines = engines @excerpt = excerpt @excerpt_separator = excerpt_separator end
Public Instance Methods
Private Instance Methods
closing()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 64 def closing @delimiters.last end
content()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 86 def content @content ? newline(@content) : '' end
engine()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 50 def engine @engine ||= @engines[@language] end
excerpt()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 80 def excerpt return '' unless @excerpt newline(@excerpt) + newline(seperator) end
matter()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 72 def matter stringifier.call(@data).then do |string| return '' if string.strip == '{}' newline(opening) + newline(string) + newline(closing) end end
newline(line)
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 90 def newline(line) line[-1] == "\n" ? line : "#{line}\n" end
opening()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 60 def opening @delimiters.first end
seperator()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 68 def seperator @excerpt_separator || closing end
stringifier()
click to toggle source
# File lib/ruby_matter/stringifier.rb, line 54 def stringifier @stringifier ||= ( engine && engine[:stringify] ) || raise(EngineError.new(language: language)) end