Class: ClassMetrix::MarkdownFormatter

Inherits:
Formatters::Base::BaseFormatter show all
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

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, expand_hashes = false, options = {})
  super
  @table_builder = Formatters::Shared::MarkdownTableBuilder.new(data, expand_hashes, @options)
end

Instance Method Details

#formatObject



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.build_expanded_table : @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)
    footer_component = Formatters::Components::FooterComponent.new(@options)
    footer_output = footer_component.generate
    output.concat(footer_output) unless footer_output.empty?
  end

  # Join with newlines, filtering out empty sections
  output.reject { |section| section.nil? || section == "" }.join("\n\n")
end