class MarkdownRubyDocumentation::MethodLinker

Attributes

root_path[R]
section_key[R]
text[R]

Public Class Methods

new(section_key:, root_path:) click to toggle source
# File lib/markdown_ruby_documentation/method_linker.rb, line 6
def initialize(section_key:, root_path:)
  @section_key = section_key
  @root_path   = root_path
end

Public Instance Methods

call(text=nil) click to toggle source
# File lib/markdown_ruby_documentation/method_linker.rb, line 11
def call(text=nil)
  @text        = text
  generate
end

Private Instance Methods

generate() click to toggle source
# File lib/markdown_ruby_documentation/method_linker.rb, line 18
def generate
  text.scan(/(?<!\^`)`{1}([\w:_\.#?]*[^`\n])\`/).each do |r|
    r = r.first
    if r =~ /(\w*::\w*)+#[\w|\?]+/ # constant with an instance method
      parts = r.split("#")
      meths = parts[-1]
      const = parts[0]
      str = "[#{meths.titleize}](#{root_path}#{const.underscore.gsub("/", "-")}##{md_id meths})"
    elsif r =~ /\w*::\w*/ # is constant
      str = "[#{r.gsub("::", " ").titleize}](#{root_path}#{md_id r})"
    else # a method
      str = "[#{r.titleize}](##{md_id r})"
    end
    @text = text.gsub("^`#{r}`", str)
  end
  text
end
md_id(str) click to toggle source
# File lib/markdown_ruby_documentation/method_linker.rb, line 36
def md_id(str)
  str.downcase.dasherize.delete(" ").delete('?').delete('!')
end