class Sem::Helpers::GitUrl

Constants

BITBUCKET_HTTP_PATTERN
GITHUB_HTTP_PATTERN
SSH_PATTERN

Attributes

repo_name[R]
repo_owner[R]
repo_provider[R]

Public Class Methods

new(url) click to toggle source
# File lib/sem/helpers/git_url.rb, line 11
def initialize(url)
  @repo_provider, @repo_owner, @repo_name = parse(url)
end

Public Instance Methods

valid?() click to toggle source
# File lib/sem/helpers/git_url.rb, line 15
def valid?
  @repo_name && @repo_provider && @repo_owner
end

Private Instance Methods

parse(url) click to toggle source
# File lib/sem/helpers/git_url.rb, line 21
def parse(url)
  ssh_match = SSH_PATTERN.match(url)
  github_http_match = GITHUB_HTTP_PATTERN.match(url)
  bitbucket_http_match = BITBUCKET_HTTP_PATTERN.match(url)

  if ssh_match
    ssh_match.captures[0..2]
  elsif github_http_match
    ["github"].concat(github_http_match.captures[1..2])
  elsif bitbucket_http_match
    ["bitbucket"].concat(bitbucket_http_match.captures[1..2])
  else
    [nil, nil, nil]
  end
end