Class: Pvectl::Formatters::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/pvectl/formatters/base.rb

Overview

This class is abstract.

Subclass and implement #format to create a formatter.

Abstract base class for output formatters.

Formatters implement the Strategy Pattern, converting model data to various output formats (table, json, yaml, wide).

Examples:

Implementing a custom formatter

class MyFormatter < Base
  def format(data, presenter, color_enabled: true, **context)
    # Return formatted string
  end
end

See Also:

Direct Known Subclasses

Json, Table, Wide, Yaml

Instance Method Summary collapse

Instance Method Details

#format(data, presenter, color_enabled: true, **context) ⇒ String

Formats data for output.

Parameters:

  • data (Array, Object)

    collection of models or single model

  • presenter (Presenters::Base)

    presenter for column/row definitions

  • color_enabled (Boolean) (defaults to: true)

    whether to apply color formatting

  • context (Hash)

    additional context (e.g., current_context for contexts)

Returns:

  • (String)

    formatted output string

Raises:

  • (NotImplementedError)

    if not implemented by subclass



31
32
33
# File 'lib/pvectl/formatters/base.rb', line 31

def format(data, presenter, color_enabled: true, **context)
  raise NotImplementedError, "#{self.class}#format must be implemented"
end