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

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

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.



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

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



38
39
40
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 38

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

#keyObject



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

def key
  String matches["key"]
end

#match?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/git/lint/parsers/trailers/collaborator.rb', line 42

def match?
  text.match? key_pattern
end

#nameObject



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

def name
  String matches["name"]
end