Sha256: 622edf2bf5c1502f90056bdd9099d6638bda65e47c4553280dba6a59b59a84cc
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
require "git/remote/parser/version" module Git module Remote class Parser class Result attr_reader :protocol, :username, :host, :owner, :repo, :html_url def initialize(protocol, username, host, owner, repo, html_url) @protocol = protocol @username = username @host = host @owner = owner @repo = repo @html_url = html_url end def to_h { protocol: protocol, username: username, host: host, owner: owner, repo: repo, html_url: html_url, } end end REGEXP = %r( (?<protocol>(http://|https://|git://|ssh://))* (?<username>[^@]+@)* (?<host>[^/]+) [/:] (?<owner>[^/]+) / (?<repo>[^/.]+) )x 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
git-remote-parser-1.0.0 | lib/git/remote/parser.rb |