Class: Lutaml::Qea::Validation::Formatters::TextFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/qea/validation/formatters/text_formatter.rb

Overview

Formats validation results as human-readable text with colors

Examples:

Basic usage

formatter = TextFormatter.new(result)
puts formatter.format

Without color

formatter = TextFormatter.new(result, color: false)
puts formatter.format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result: nil, **options) ⇒ TextFormatter

Creates a new text formatter

(default: true) (default: false)

Parameters:

  • result (ValidationResult) (defaults to: nil)

    The validation result to format

  • options (Hash)

    Formatting options

Options Hash (**options):

  • :color (Boolean)

    Enable colored output

  • :verbose (Boolean)

    Show all messages

  • :limit (Integer)

    Maximum messages per category



28
29
30
31
32
33
34
35
# File 'lib/lutaml/qea/validation/formatters/text_formatter.rb', line 28

def initialize(result: nil, **options)
  @result = result
  @options = {
    color: true,
    verbose: false,
    limit: nil,
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/lutaml/qea/validation/formatters/text_formatter.rb', line 17

def options
  @options
end

#resultObject (readonly)

Returns the value of attribute result.



17
18
19
# File 'lib/lutaml/qea/validation/formatters/text_formatter.rb', line 17

def result
  @result
end

Instance Method Details

#formatString

Formats the validation result as text

Returns:

  • (String)

    Formatted text output



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/lutaml/qea/validation/formatters/text_formatter.rb', line 40

def format # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  lines = []
  lines << header
  lines << ""
  lines << summary
  lines << ""

  if result.has_errors?
    lines << section_header("ERRORS", result.errors.size)
    lines << format_messages(result.errors)
    lines << ""
  end

  if result.has_warnings?
    lines << section_header("WARNINGS", result.warnings.size)
    lines << format_messages(result.warnings)
    lines << ""
  end

  if result.has_info? && options[:verbose]
    lines << section_header("INFO", result.info.size)
    lines << format_messages(result.info)
    lines << ""
  end

  lines << footer
  lines.join("\n")
end