Sha256: 922430f3320294fc268ad8183493a9f66ee6e7e716f0816377d11deb2616ca64

Contents?: true

Size: 607 Bytes

Versions: 5

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true

module Tocer
  module Transformers
    # Finds appropriate header transformer for matching pattern.
    class Finder
      TRANSFORMERS = {/\[.+\]\(.+\)/ => Transformers::Link, /.*/ => Transformers::Text}.freeze

      def initialize transformers: TRANSFORMERS
        @transformers = transformers
      end

      def call markdown
        transformers.find { |pattern, transformer| break transformer if pattern.match? markdown }
                    .then { |transformer| transformer.new markdown }
      end

      private

      attr_reader :transformers
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tocer-12.2.0 lib/tocer/transformers/finder.rb
tocer-12.1.0 lib/tocer/transformers/finder.rb
tocer-12.0.4 lib/tocer/transformers/finder.rb
tocer-12.0.3 lib/tocer/transformers/finder.rb
tocer-12.0.2 lib/tocer/transformers/finder.rb