Class: Pvectl::Formatters::Registry
- Inherits:
-
Object
- Object
- Pvectl::Formatters::Registry
- Defined in:
- lib/pvectl/formatters/registry.rb
Overview
Registry for looking up formatters by name.
Implements the Registry Pattern to map format names (“table”, “json”, “yaml”, “wide”) to formatter classes.
Constant Summary collapse
- FORMATS =
Mapping of format names to formatter classes.
{ "table" => Table, "wide" => Wide, "json" => Json, "yaml" => Yaml }.freeze
Class Method Summary collapse
-
.available_formats ⇒ Array<String>
Returns list of available format names.
-
.for(format_name) ⇒ Base
Gets a formatter instance for the specified format.
-
.supported?(format_name) ⇒ Boolean
Checks if a format is supported.
Class Method Details
.available_formats ⇒ Array<String>
Returns list of available format names.
54 55 56 |
# File 'lib/pvectl/formatters/registry.rb', line 54 def available_formats FORMATS.keys end |
.for(format_name) ⇒ Base
Gets a formatter instance for the specified format.
41 42 43 44 45 46 |
# File 'lib/pvectl/formatters/registry.rb', line 41 def for(format_name) formatter_class = FORMATS[format_name.to_s] raise ArgumentError, "Unknown format: #{format_name}" unless formatter_class formatter_class.new end |
.supported?(format_name) ⇒ Boolean
Checks if a format is supported.
66 67 68 |
# File 'lib/pvectl/formatters/registry.rb', line 66 def supported?(format_name) FORMATS.key?(format_name.to_s) end |