Class: RenderAsMarkdown::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/render-as-markdown/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, text = nil, hint = nil) ⇒ Link

Returns a new instance of Link.



8
9
10
# File 'lib/render-as-markdown/link.rb', line 8

def initialize url, text=nil, hint=nil
  @url, @text, @hint = url.to_s, text.to_s, hint.to_s
end

Instance Attribute Details

#hintObject

TODO: look up Github in-document link reference and implement it (e.g. “[A Header](#a-header)” )



6
7
8
# File 'lib/render-as-markdown/link.rb', line 6

def hint
  @hint
end

#textObject

TODO: look up Github in-document link reference and implement it (e.g. “[A Header](#a-header)” )



6
7
8
# File 'lib/render-as-markdown/link.rb', line 6

def text
  @text
end

#urlObject

TODO: look up Github in-document link reference and implement it (e.g. “[A Header](#a-header)” )



6
7
8
# File 'lib/render-as-markdown/link.rb', line 6

def url
  @url
end

Instance Method Details

#renderObject Also known as: to_s



12
13
14
15
16
# File 'lib/render-as-markdown/link.rb', line 12

def render
  text = @text.empty? ? @url : @text
  hint = " \"#{@hint}\"" unless @hint.empty?
  "[#{text}](#{@url}#{hint})"
end