class MarkdownRubyDocumentation::MarkdownPresenter
Attributes
items[R]
summary[R]
title_key[R]
Public Class Methods
new(items: nil, summary:, title_key:, skip_blanks: true)
click to toggle source
# 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
Public Instance Methods
call(items=nil)
click to toggle source
# 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
Private Instance Methods
class_level_comment()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 32 def class_level_comment @class_level_comment ||= (items.delete(:class_level_comment) || {}) if @class_level_comment[:text] "#{@class_level_comment[:text]}\n" else "" end end
class_methods()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 46 def class_methods @class_methods ||= method_presenters("MarkdownRubyDocumentation::ClassMethod") end
instances_methods()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 42 def instances_methods @instance_methods ||= method_presenters("MarkdownRubyDocumentation::InstanceMethod") end
item_types()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 28 def item_types @item_types ||= items.group_by { |_, hash| hash[:method_object].class.name } end
method_presenters(type, heading="
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 61 def method_presenters(type, heading="##") type_methods = item_types.delete(type) || [] order_by_location(type_methods).map do |(name, hash)| %[#{heading} #{name.to_s.titleize}\n#{hash[:text]}] unless hash[:text].blank? end.join("\n\n") end
nothing_to_display?()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 78 def nothing_to_display? [class_level_comment, instances_methods, class_methods, null_methods].all?(&:empty?) end
null_methods()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 50 def null_methods @null_methods ||= begin md = method_presenters("MarkdownRubyDocumentation::NullMethod", "###") if md.blank? "" else "\n## Reference Values\n" << md end end end
order_by_location(items)
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 68 def order_by_location(items) items.sort_by do |(name, hash)| hash[:method_object].source_location rescue name # NullMethod has no source_location end end
other_types!()
click to toggle source
# File lib/markdown_ruby_documentation/markdown_presenter.rb, line 74 def other_types! raise "Unhandled methods types: #{item_types}" unless item_types.empty? end