Class: Git::Lint::Parsers::Trailers::Collaborator

Inherits:
Object
  • Object
show all
Defined in:
lib/git/lint/parsers/trailers/collaborator.rb

Overview

Parses collaborator information within a commit trailer.

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(text, key_pattern: DEFAULT_KEY_PATTERN, match_pattern: DEFAULT_MATCH_PATTERN) ⇒ Collaborator

Returns a new instance of Collaborator.



21
22
23
24
25
26
27
28
29
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 21

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

Instance Method Details

#emailObject



35
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 35

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

#keyObject



31
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 31

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

#match?Boolean

Returns:

  • (Boolean)


37
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 37

def match? = text.match?(key_pattern)

#nameObject



33
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 33

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