Class: MarkdownRubyDocumentation::GitHubLink::FileUrl
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::GitHubLink::FileUrl
- Defined in:
- lib/markdown_ruby_documentation/git_hub_link.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #blob(file) ⇒ Object
-
#initialize(file_path:, base_url: GitHubProject.url, root: GitHubProject.root_path) ⇒ FileUrl
constructor
A new instance of FileUrl.
- #link(file, lineno = nil) ⇒ Object
- #relative_path(file) ⇒ Object
- #to_pathname ⇒ Object
- #to_s ⇒ Object
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_url ⇒ Object (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_path ⇒ Object (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 |
#root ⇒ Object (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 |
#link(file, lineno = nil) ⇒ Object
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_pathname ⇒ Object
37 38 39 |
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 37 def to_pathname Pathname(to_s) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/markdown_ruby_documentation/git_hub_link.rb', line 33 def to_s link(file_path) end |