Class: Pvectl::Formatters::Base Abstract
- Inherits:
-
Object
- Object
- Pvectl::Formatters::Base
- Defined in:
- lib/pvectl/formatters/base.rb,
sig/pvectl/formatters/base.rbs
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).
Instance Method Summary collapse
-
#collection?(data) ⇒ Boolean
Determines if data is a collection or single resource.
-
#format(data, presenter, color_enabled: true, **context) ⇒ String
Formats data for output.
-
#normalize_nil(value, nil_placeholder = "-") ⇒ Object, String
Normalizes nil values for display.
Instance Method Details
#collection?(data) ⇒ Boolean
Determines if data is a collection or single resource.
41 42 43 |
# File 'lib/pvectl/formatters/base.rb', line 41 def collection?(data) data.is_a?(Array) end |
#format(data, presenter, color_enabled: true, **context) ⇒ String
Formats data for output.
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 |
#normalize_nil(value, nil_placeholder = "-") ⇒ Object, String
Normalizes nil values for display.
50 51 52 |
# File 'lib/pvectl/formatters/base.rb', line 50 def normalize_nil(value, nil_placeholder = "-") value.nil? ? nil_placeholder : value end |