Class: ClassMetrix::MarkdownFormatter
- Inherits:
-
Formatters::Base::BaseFormatter
- Object
- Formatters::Base::BaseFormatter
- ClassMetrix::MarkdownFormatter
- Defined in:
- lib/class_metrix/formatters/markdown_formatter.rb
Instance Attribute Summary
Attributes inherited from Formatters::Base::BaseFormatter
#data, #expand_hashes, #options
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(data, expand_hashes = false, options = {}) ⇒ MarkdownFormatter
constructor
A new instance of MarkdownFormatter.
Constructor Details
#initialize(data, expand_hashes = false, options = {}) ⇒ MarkdownFormatter
Returns a new instance of MarkdownFormatter.
11 12 13 14 |
# File 'lib/class_metrix/formatters/markdown_formatter.rb', line 11 def initialize(data, = false, = {}) super @table_builder = Formatters::Shared::MarkdownTableBuilder.new(data, , @options) end |
Instance Method Details
#format ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/class_metrix/formatters/markdown_formatter.rb', line 16 def format return "" if @data[:headers].empty? || @data[:rows].empty? output = [] # : Array[String] # Add header sections (title, classes, extraction info) if @options.fetch(:show_metadata, true) header_component = Formatters::Components::GenericHeaderComponent.new(@data, @options.merge(format: :markdown)) header_output = header_component.generate output.concat(header_output) unless header_output.empty? end # Add main table table_data = @expand_hashes ? @table_builder. : @table_builder.build_simple_table table_output = render_markdown_table(table_data) unless table_output.empty? # Join table rows with single newlines, then add as one section output << table_output.join("\n") end # Add missing behaviors summary if @options.fetch(:show_missing_summary, false) missing_component = Formatters::Components::MissingBehaviorsComponent.new(@data, @options) missing_output = missing_component.generate output.concat(missing_output) unless missing_output.empty? end # Add footer if @options.fetch(:show_footer, true) = Formatters::Components::FooterComponent.new(@options) = .generate output.concat() unless .empty? end # Join with newlines, filtering out empty sections output.reject { |section| section.nil? || section == "" }.join("\n\n") end |