Class: Git::Remote::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/git/remote/parser.rb,
lib/git/remote/parser/version.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

REGEXP =
%r(
  (?<protocol>(http://|https://|git://|ssh://))*
  (?<username>[^@]+@)*
  (?<host>[^/]+)
  [/:]
  (?<owner>[^/]+)
  /
  (?<repo>[^/.]+)
)x
VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#parse(remote_uri) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/git/remote/parser.rb', line 40

def parse(remote_uri)
  if matched = remote_uri.match(REGEXP)
    Result.new(
      matched[:protocol],
      matched[:username] && matched[:username].delete("@".freeze),
      matched[:host],
      matched[:owner],
      matched[:repo],
      File.join("https://#{matched[:host]}", matched[:owner],matched[:repo]),
    )
  end
end