Sha256: 3e7637b4d030dd108e0135cc07d1d96a62af9e628418a8cbdc909e83bb7808f2

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Parsers
      module Trailers
        # Parses collaborator information within a commit trailer.
        class Collaborator
          DEFAULT_KEY_PATTERN = /\ACo.*Authored.*By.*\Z/i

          DEFAULT_MATCH_PATTERN = /
            (?<key>\A.+)         # Key (anchored to start of line).
            (?<delimiter>:)      # Key delimiter.
            (?<key_space>\s?)    # Space delimiter (optional).
            (?<name>.*?)         # Collaborator name (smallest possible).
            (?<name_space>\s?)   # Space delimiter (optional).
            (?<email><.+>)?      # Collaborator email (optional).
            \Z                   # End of line.
          /x

          def initialize text,
                         key_pattern: DEFAULT_KEY_PATTERN,
                         match_pattern: DEFAULT_MATCH_PATTERN

            @text = String text
            @key_pattern = key_pattern
            @match_pattern = match_pattern
            @matches = build_matches
          end

          def key = String(matches["key"])

          def name = String(matches["name"])

          def email = String(matches["email"]).delete_prefix("<").delete_suffix(">")

          def match? = text.match?(key_pattern)

          private

          attr_reader :text, :key_pattern, :match_pattern, :matches

          def build_matches
            text.match(match_pattern).then { |data| data ? data.named_captures : Hash.new }
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
git-lint-4.6.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.5.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.4.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.3.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.2.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.1.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.0.1 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-4.0.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.3.2 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.3.1 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.3.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.2.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.1.0 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.0.2 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.0.1 lib/git/lint/parsers/trailers/collaborator.rb
git-lint-3.0.0 lib/git/lint/parsers/trailers/collaborator.rb