Class: GitMarkdown::RemoteParser

Inherits:
Object
  • Object
show all
Defined in:
lib/git/markdown/remote_parser.rb

Constant Summary collapse

PATTERNS =
{
  github: %r{(?:github\.com|github\.enterprise)[/:]([^/]+)/([^/]+?)(?:\.git)?$},
  gitlab: %r{gitlab\.com[/:]([^/]+)/([^/]+?)(?:\.git)?$}
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RemoteParser

Returns a new instance of RemoteParser.



12
13
14
15
# File 'lib/git/markdown/remote_parser.rb', line 12

def initialize(url)
  @url = url
  parse!
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



10
11
12
# File 'lib/git/markdown/remote_parser.rb', line 10

def owner
  @owner
end

#providerObject (readonly)

Returns the value of attribute provider.



10
11
12
# File 'lib/git/markdown/remote_parser.rb', line 10

def provider
  @provider
end

#repoObject (readonly)

Returns the value of attribute repo.



10
11
12
# File 'lib/git/markdown/remote_parser.rb', line 10

def repo
  @repo
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/git/markdown/remote_parser.rb', line 10

def url
  @url
end

Class Method Details

.from_git_remote(remote = "origin") ⇒ Object



21
22
23
24
25
26
# File 'lib/git/markdown/remote_parser.rb', line 21

def self.from_git_remote(remote = "origin")
  url = git_remote_url(remote)
  return nil if url.nil? || url.empty?

  new(url)
end

.parse(url) ⇒ Object



17
18
19
# File 'lib/git/markdown/remote_parser.rb', line 17

def self.parse(url)
  new(url)
end

Instance Method Details

#full_nameObject



32
33
34
# File 'lib/git/markdown/remote_parser.rb', line 32

def full_name
  "#{@owner}/#{@repo}" if valid?
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/git/markdown/remote_parser.rb', line 28

def valid?
  !@provider.nil?
end