Class: GithubUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/github_url.rb,
lib/github_url/version.rb

Defined Under Namespace

Classes: Invalid

Constant Summary collapse

GITHUB_HOST =
"github.com".freeze
VERSION =
"0.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, default_branch: "master", host: GITHUB_HOST) ⇒ GithubUrl

Returns a new instance of GithubUrl.



9
10
11
12
13
14
15
# File 'lib/github_url.rb', line 9

def initialize(url:, default_branch: "master", host: GITHUB_HOST)
  @default_branch = default_branch
  @url = url
  @host = host

  validate_url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/github_url.rb', line 2

def url
  @url
end

Instance Method Details

#branchObject



25
26
27
# File 'lib/github_url.rb', line 25

def branch
  default_branch? ? @default_branch : url_path[3]
end

#organizationObject



17
18
19
# File 'lib/github_url.rb', line 17

def organization
  url_path[0]
end

#pathObject



29
30
31
# File 'lib/github_url.rb', line 29

def path
  default_branch? ? File.join(url_path[2..-1]) : File.join(url_path[4..-1].to_a)
end

#repositoryObject



21
22
23
# File 'lib/github_url.rb', line 21

def repository
  url_path[1]
end