Sha256: fb2fbbb4d79fadfa876313c3a8b5debe12b6ff9bdeeeb0239d098cf1c84184af

Contents?: true

Size: 959 Bytes

Versions: 6

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

module FrontMatterParser
  module SyntaxParser
    # This is just a helper to allow creating syntax parsers with a more terse
    # syntax, without the need of explicitly creating descendant classes for the
    # most general cases. See {SyntaxParser} for examples in use.
    module Factorizable
      # @param delimiters [String] Splat arguments with all comment delimiters
      # used by the parser
      #
      # @return [Object] A base class of self with a `delimiters` class method
      # added which returns an array with given comment delimiters
      def [](*delimiters)
        delimiters = delimiters.map { |delimiter| Regexp.escape(delimiter) }
        create_base_class(delimiters)
      end

      private

      def create_base_class(delimiters)
        parser = Class.new(self)
        parser.define_singleton_method(:delimiters) do
          delimiters
        end
        parser
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
front_matter_parser-1.0.1 lib/front_matter_parser/syntax_parser/factorizable.rb
front_matter_parser-1.0.0 lib/front_matter_parser/syntax_parser/factorizable.rb
front_matter_parser-0.2.1 lib/front_matter_parser/syntax_parser/factorizable.rb
front_matter_parser-0.2.0 lib/front_matter_parser/syntax_parser/factorizable.rb
front_matter_parser-0.1.1 lib/front_matter_parser/syntax_parser/factorizable.rb
front_matter_parser-0.1.0 lib/front_matter_parser/syntax_parser/factorizable.rb