Class: Lutaml::Xsd::Formatters::Registry
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Formatters::Registry
- Defined in:
- lib/lutaml/xsd/formatters/registry.rb
Overview
Registry for dynamically managing formatter classes Enables plugin-style formatter registration
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all registered formatters.
-
#count ⇒ Integer
Get count of registered formatters.
-
#create(name) ⇒ Base
Create a formatter instance by name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(name, formatter_class) ⇒ Object
Register a formatter class.
-
#supported?(name) ⇒ Boolean
Check if a format is supported.
-
#supported_formats ⇒ Array<String>
Get list of supported format names.
-
#unregister(name) ⇒ Class?
Unregister a formatter.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
11 12 13 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 11 def initialize @formatters = {} end |
Instance Method Details
#clear ⇒ Object
Clear all registered formatters
64 65 66 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 64 def clear @formatters.clear end |
#count ⇒ Integer
Get count of registered formatters
70 71 72 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 70 def count @formatters.size end |
#create(name) ⇒ Base
Create a formatter instance by name
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 32 def create(name) formatter_class = @formatters[name.to_s] unless formatter_class raise ArgumentError, "Unknown format: #{name}. " \ "Supported formats: #{supported_formats.join(', ')}" end formatter_class.new end |
#register(name, formatter_class) ⇒ Object
Register a formatter class
19 20 21 22 23 24 25 26 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 19 def register(name, formatter_class) unless formatter_class < Base raise ArgumentError, "Formatter must inherit from Lutaml::Xsd::Formatters::Base" end @formatters[name.to_s] = formatter_class end |
#supported?(name) ⇒ Boolean
Check if a format is supported
52 53 54 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 52 def supported?(name) @formatters.key?(name.to_s) end |
#supported_formats ⇒ Array<String>
Get list of supported format names
45 46 47 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 45 def supported_formats @formatters.keys.sort end |
#unregister(name) ⇒ Class?
Unregister a formatter
59 60 61 |
# File 'lib/lutaml/xsd/formatters/registry.rb', line 59 def unregister(name) @formatters.delete(name.to_s) end |