Class: Lutaml::Xsd::PackageTreeFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/package_tree_formatter.rb

Overview

Formats LXR package contents as a colorized tree structure

Responsibilities:

  • Extract and organize package file listing

  • Generate colorized tree output with appropriate icons

  • Handle different output formats (tree, flat)

  • Calculate and display file sizes

Examples:

Basic usage

formatter = PackageTreeFormatter.new(package_path)
puts formatter.format

With options

formatter = PackageTreeFormatter.new(
  package_path,
  show_sizes: true,
  no_color: false,
  format: :tree
)
puts formatter.format

Constant Summary collapse

COLORS =

Color scheme for different file types

{
  directory: %i[cyan bold],
  xsd_file: :green,
  metadata_file: :yellow,
  serialized_file: :blue,
  index_file: :magenta,
  file_size: :black,
  summary_label: [:bold],
  summary_value: %i[cyan bold],
}.freeze
ICONS =

Icons for different file types

{
  directory: "📁",
  metadata: "📋",
  xsd: "📄",
  index: "🔍",
  mapping: "🔖",
  relation: "🔗",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_path, options = {}) ⇒ PackageTreeFormatter

Initialize formatter

Parameters:

  • package_path (String)

    Path to .lxr package file

  • options (Hash) (defaults to: {})

    Formatting options

Options Hash (options):

  • :show_sizes (Boolean)

    Show file sizes (default: false)

  • :no_color (Boolean)

    Disable colored output (default: false)

  • :format (Symbol)

    Output format :tree or :flat (default: :tree)



59
60
61
62
63
64
65
66
# File 'lib/lutaml/xsd/package_tree_formatter.rb', line 59

def initialize(package_path, options = {})
  @package_path = package_path
  @options = {
    show_sizes: false,
    no_color: false,
    format: :tree,
  }.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



50
51
52
# File 'lib/lutaml/xsd/package_tree_formatter.rb', line 50

def options
  @options
end

#package_pathObject (readonly)

Returns the value of attribute package_path.



50
51
52
# File 'lib/lutaml/xsd/package_tree_formatter.rb', line 50

def package_path
  @package_path
end

Instance Method Details

#formatString

Format package contents as tree

Returns:

  • (String)

    Formatted tree output



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/lutaml/xsd/package_tree_formatter.rb', line 71

def format
  entries = extract_entries
  stats = calculate_statistics(entries)

  output = []
  output << format_header(stats[:total_size])
  output << format_entries(entries) if options[:format] == :tree
  output << format_flat_list(entries) if options[:format] == :flat
  output << ""
  output << format_summary(stats)

  output.join("\n")
end