Sha256: b38df8752ea53afe6c3a055fdc83cdf149933923903ac44467695a2e7db8654d

Contents?: true

Size: 691 Bytes

Versions: 1

Compression:

Stored size: 691 Bytes

Contents

module Ahnnotate
  module Function
    class Format
      attr_reader :comment

      def initialize(comment:)
        @comment = comment
      end

      def call(table, content)
        table.string(comment: comment) + "\n" + strip_schema(content)
      end

      private

      def strip_schema(content)
        matches = pattern.match(content)

        if matches
          matches["post"]
        else
          content
        end
      end

      def pattern
        @pattern ||=
          begin
            newline = /\r?\n\r?/

            /\A#{comment}\s==\sSchema\sInfo#{newline}?(?:^#{comment}[^\n]*$#{newline})*#{newline}(?<post>.*)/m
          end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahnnotate-0.2.0 lib/ahnnotate/function/format.rb