Sha256: 95c2b5ad631c9891f9b858aafad6cf3552955e2aff771c2808465fcc62498a6f

Contents?: true

Size: 492 Bytes

Versions: 10

Compression:

Stored size: 492 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 self.call markdown
        TRANSFORMERS.find { |pattern, transformer| break transformer if pattern.match? markdown }
                    .then { |transformer| transformer.new markdown }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tocer-10.3.0 lib/tocer/transformers/finder.rb
tocer-10.2.0 lib/tocer/transformers/finder.rb
tocer-10.1.1 lib/tocer/transformers/finder.rb
tocer-10.1.0 lib/tocer/transformers/finder.rb
tocer-10.0.1 lib/tocer/transformers/finder.rb
tocer-10.0.0 lib/tocer/transformers/finder.rb
tocer-9.1.2 lib/tocer/transformers/finder.rb
tocer-9.1.1 lib/tocer/transformers/finder.rb
tocer-9.1.0 lib/tocer/transformers/finder.rb
tocer-9.0.0 lib/tocer/transformers/finder.rb