Sha256: 161ab527715069229d9bd5540d92affdfa8a2b868910c43926966b05ad1bd36c

Contents?: true

Size: 631 Bytes

Versions: 7

Compression:

Stored size: 631 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

7 entries across 7 versions & 1 rubygems

Version Path
tocer-12.0.1 lib/tocer/transformers/finder.rb
tocer-12.0.0 lib/tocer/transformers/finder.rb
tocer-11.1.0 lib/tocer/transformers/finder.rb
tocer-11.0.0 lib/tocer/transformers/finder.rb
tocer-10.5.0 lib/tocer/transformers/finder.rb
tocer-10.4.1 lib/tocer/transformers/finder.rb
tocer-10.4.0 lib/tocer/transformers/finder.rb