Sha256: 48d6026776572781de9db74c38902f89108cd61f58b8b5271c1c8b221a74b0ea

Contents?: true

Size: 846 Bytes

Versions: 4

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

module Pragmater
  module Formatters
    # Formats general pragmas in a consistent manner.
    class General
      PATTERN = /
        \A      # Start of line.
        \#      # Start of comment.
        \s?     # Space - optional.
        \w+     # Key - One or more word characters only.
        :       # Delimiter.
        \s?     # Space - optional.
        [\w-]+  # Value - One or more word or dash characters.
        \Z      # End of line.
      /x.freeze

      def initialize string, pattern: PATTERN
        @string = string
        @pattern = pattern
      end

      def call
        return string unless string.match? pattern

        string.split(":").then { |key, value| "# #{key.gsub(/\#\s?/, "")}: #{value.strip}" }
      end

      private

      attr_reader :string, :pattern
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pragmater-8.3.0 lib/pragmater/formatters/general.rb
pragmater-8.2.0 lib/pragmater/formatters/general.rb
pragmater-8.1.0 lib/pragmater/formatters/general.rb
pragmater-8.0.0 lib/pragmater/formatters/general.rb