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"
VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, default_branch = "master") ⇒ GithubUrl

Returns a new instance of GithubUrl.



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

def initialize(url, default_branch = "master")
  @default_branch = default_branch
  @url = url

  validate_url
end

Instance Attribute Details

#default_branchObject

Returns the value of attribute default_branch.



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

def default_branch
  @default_branch
end

#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



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

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

#organizationObject



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

def organization
  url_path[0]
end

#pathObject



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

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

#repositoryObject



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

def repository
  url_path[1]
end