Class: Json::Schema::Diff::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema/diff/formatter.rb

Overview

Formats diff results into human-readable or machine-readable output

Supports both pretty-printed colorized output for humans and JSON output for machines. Handles ANSI color codes and provides structured formatting of change information.

Constant Summary collapse

COLORS =

ANSI color codes for terminal output

{
  red: "\e[31m",
  green: "\e[32m",
  yellow: "\e[33m",
  blue: "\e[34m",
  magenta: "\e[35m",
  cyan: "\e[36m",
  reset: "\e[0m"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(format = "pretty", use_color = true) ⇒ Formatter

Initialize a new Formatter



26
27
28
29
# File 'lib/json/schema/diff/formatter.rb', line 26

def initialize(format = "pretty", use_color = true)
  @format = format
  @use_color = use_color
end

Instance Method Details

#format(changes) ⇒ String

Formats an array of changes into the specified output format



35
36
37
38
39
40
41
42
# File 'lib/json/schema/diff/formatter.rb', line 35

def format(changes)
  case @format
  when "json"
    format_json(changes)
  else
    format_pretty(changes)
  end
end