Class: MarkdownRubyDocumentation::RelativeLinkConverter
- Inherits:
-
Object
- Object
- MarkdownRubyDocumentation::RelativeLinkConverter
- Defined in:
- lib/markdown_ruby_documentation/relative_link_converter.rb
Instance Attribute Summary collapse
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #call(text = nil) ⇒ Object
- #create_relative_link(link) ⇒ Object
- #generate ⇒ Object
-
#initialize(subject:) ⇒ RelativeLinkConverter
constructor
A new instance of RelativeLinkConverter.
- #path ⇒ Object
Constructor Details
#initialize(subject:) ⇒ RelativeLinkConverter
Returns a new instance of RelativeLinkConverter.
5 6 7 8 |
# File 'lib/markdown_ruby_documentation/relative_link_converter.rb', line 5 def initialize(subject:) @root_path = root_path @subject = subject end |
Instance Attribute Details
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
3 4 5 |
# File 'lib/markdown_ruby_documentation/relative_link_converter.rb', line 3 def root_path @root_path end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/markdown_ruby_documentation/relative_link_converter.rb', line 3 def subject @subject end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/markdown_ruby_documentation/relative_link_converter.rb', line 3 def text @text end |
Instance Method Details
#call(text = nil) ⇒ Object
10 11 12 13 |
# File 'lib/markdown_ruby_documentation/relative_link_converter.rb', line 10 def call(text=nil) @text = text generate end |
#create_relative_link(link) ⇒ Object
36 37 38 39 40 41 42 |
# 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 ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
26 27 28 29 30 31 32 33 34 |
# 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 |