class MarkdownRubyDocumentation::RelativeLinkConverter
Attributes
root_path[R]
subject[R]
text[R]
Public Class Methods
new(subject:)
click to toggle source
# File lib/markdown_ruby_documentation/relative_link_converter.rb, line 5 def initialize(subject:) @root_path = root_path @subject = subject end
Public Instance Methods
call(text=nil)
click to toggle source
# File lib/markdown_ruby_documentation/relative_link_converter.rb, line 10 def call(text=nil) @text = text generate end
create_relative_link(link)
click to toggle source
# File lib/markdown_ruby_documentation/relative_link_converter.rb, line 36 def create_relative_link(link) if link.include?("#") "#" + link.split("#").last else link end end
generate()
click to toggle source
# File lib/markdown_ruby_documentation/relative_link_converter.rb, line 15 def generate text.scan(/\[[\w?\-_!0-9 ]*\]\((.*?)\)/).each do |r| link = r.first if link.include?(path.to_s) @text = text.gsub(link, create_relative_link(link)) end end text end
path()
click to toggle source
# File lib/markdown_ruby_documentation/relative_link_converter.rb, line 26 def path @path ||= begin method = MarkdownRubyDocumentation::Method.create(subject.name, null_method: true, context: Kernel) parts = method.context_name.to_s.split("::").reject(&:blank?) path = parts.map { |p| p.underscore }.join("/") path = "#{path}.md#{method.type_symbol}#{method.name}" MarkdownRubyDocumentation::GitHubLink::FileUrl.new(file_path: File.join(MarkdownRubyDocumentation::Generate.output_object.relative_dir, path)).to_s end end