Class: MarkdownRubyDocumentation::GitHubLink::FileUrl

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, base_url: GitHubProject.url, root: GitHubProject.root_path) ⇒ FileUrl



27
28
29
30
31
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 27

def initialize(file_path:, base_url: GitHubProject.url, root: GitHubProject.root_path)
  @file_path = file_path
  @base_url  = base_url
  @root      = root
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

Instance Method Details

#blob(file) ⇒ Object



49
50
51
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 49

def blob(file)
  GitHubProject.branch
end


41
42
43
44
45
46
47
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 41

def link(file, lineno=nil)
  str = File.join(base_url, "blob", blob(file), relative_path(file))
  unless lineno.nil?
    str << "#L#{lineno}"
  end
  str.chomp.gsub("https://github.com///github.com/", "https://github.com/")
end

#relative_path(file) ⇒ Object



53
54
55
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 53

def relative_path(file)
  file.sub(root, "")
end

#to_pathnameObject



37
38
39
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 37

def to_pathname
  Pathname(to_s)
end

#to_sObject



33
34
35
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 33

def to_s
  link(file_path)
end