Class: JekyllGithubContent::GithubUriParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_github_content.rb

Constant Summary collapse

GITHUB_URI_ROOT =
'https://github.com/'
GITHUB_RAW_URI_ROOT =
'https://raw.githubusercontent.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GithubUriParser

Returns a new instance of GithubUriParser.



15
16
17
18
19
20
21
# File 'lib/jekyll_github_content.rb', line 15

def initialize(path)
  relative_path = path.sub(/^https?\:\/\//, '').sub(/^github.com/, '')
  url_chunks = relative_path.split('/').delete_if { |e| e.empty? }

  @user, @repo, blob, @branch = url_chunks[0..3]
  @file = File.join(url_chunks[4..-1])
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



13
14
15
# File 'lib/jekyll_github_content.rb', line 13

def file
  @file
end

#repoObject (readonly)

Returns the value of attribute repo.



13
14
15
# File 'lib/jekyll_github_content.rb', line 13

def repo
  @repo
end

#userObject (readonly)

Returns the value of attribute user.



13
14
15
# File 'lib/jekyll_github_content.rb', line 13

def user
  @user
end

Instance Method Details

#get_raw_file_uriObject



23
24
25
# File 'lib/jekyll_github_content.rb', line 23

def get_raw_file_uri
  File.join(GITHUB_RAW_URI_ROOT, @user, @repo, @branch, @file)
end

#get_repo_uriObject



31
32
33
# File 'lib/jekyll_github_content.rb', line 31

def get_repo_uri
  File.join(GITHUB_URI_ROOT, @user, @repo)
end

#get_user_uriObject



27
28
29
# File 'lib/jekyll_github_content.rb', line 27

def get_user_uri
  File.join(GITHUB_URI_ROOT, @user)
end