Class: MarkdownRubyDocumentation::MarkdownPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_ruby_documentation/markdown_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items: nil, summary:, title_key:, skip_blanks: true) ⇒ MarkdownPresenter

Returns a new instance of MarkdownPresenter.



6
7
8
9
10
11
12
# File 'lib/markdown_ruby_documentation/markdown_presenter.rb', line 6

def initialize(items: nil, summary:, title_key:, skip_blanks: true)
  @items         = items
  @summary       = summary
  @title_key     = title_key
  @skip_blanks   = skip_blanks
  @present_items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



4
5
6
# File 'lib/markdown_ruby_documentation/markdown_presenter.rb', line 4

def items
  @items
end

#summaryObject (readonly)

Returns the value of attribute summary.



4
5
6
# File 'lib/markdown_ruby_documentation/markdown_presenter.rb', line 4

def summary
  @summary
end

#title_keyObject (readonly)

Returns the value of attribute title_key.



4
5
6
# File 'lib/markdown_ruby_documentation/markdown_presenter.rb', line 4

def title_key
  @title_key
end

Instance Method Details

#call(items = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/markdown_ruby_documentation/markdown_presenter.rb', line 14

def call(items=nil)
  @items ||= items
  return "" if nothing_to_display?
  md = ["# #{summary.title}", "#{summary.summary}\n".gsub(/\n\n\n/, "\n\n"), class_level_comment, instances_methods, class_methods, "#{null_methods}\n".gsub(/\n\n\n/, "\n\n")]
         .reject(&:empty?)
         .join("\n")
         .gsub(/[\n]{3,}/, "\n\n")
         .gsub(/[\n]+\Z/, "\n\n")
  other_types!
  md
end