Class: JekyllGithubSample::FileHelper

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

Constant Summary collapse

GITHUB_RAW_URI =
'https://raw.githubusercontent.com/'
GITHUB_URI =
'https://github.com/'
WEB_URI_PART =
'blob'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileHelper

Returns a new instance of FileHelper.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jekyll_github_sample/file_helper.rb', line 10

def initialize(path)
  @path = path
  parts = @path.split('/').delete_if { |e| e.empty? }
  if parts.include? WEB_URI_PART
    @user, @project_name, @blob, @commitish_or_branch = parts[0..3]
    @filename = File.join(parts[4..-1])
  else
    @user, @project_name, @commitish_or_branch = parts[0..2]
    @filename = File.join(parts[3..-1])
  end
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/jekyll_github_sample/file_helper.rb', line 8

def filename
  @filename
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



8
9
10
# File 'lib/jekyll_github_sample/file_helper.rb', line 8

def project_name
  @project_name
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/jekyll_github_sample/file_helper.rb', line 8

def user
  @user
end

Instance Method Details

#raw_uriObject



30
31
32
# File 'lib/jekyll_github_sample/file_helper.rb', line 30

def raw_uri
  File.join(GITHUB_RAW_URI, @user, @project_name, @commitish_or_branch, @filename)
end

#user_uriObject



22
23
24
# File 'lib/jekyll_github_sample/file_helper.rb', line 22

def user_uri
  File.join(GITHUB_URI, @user)
end

#web_uriObject



26
27
28
# File 'lib/jekyll_github_sample/file_helper.rb', line 26

def web_uri
  File.join(GITHUB_URI, @user, @project_name, WEB_URI_PART, @commitish_or_branch, @filename)
end