Class: HammerCLI::Output::Formatters::FormatterLibrary
- Inherits:
-
Object
- Object
- HammerCLI::Output::Formatters::FormatterLibrary
- Defined in:
- lib/hammer_cli/output/formatters.rb
Overview
Registry for formatters
Instance Method Summary collapse
- #formatter_for_type(type) ⇒ Object
-
#initialize(formatter_map = {}) ⇒ FormatterLibrary
constructor
A new instance of FormatterLibrary.
- #register_formatter(type, *formatters) ⇒ Object
Constructor Details
#initialize(formatter_map = {}) ⇒ FormatterLibrary
Returns a new instance of FormatterLibrary.
6 7 8 9 10 11 12 |
# File 'lib/hammer_cli/output/formatters.rb', line 6 def initialize(formatter_map={}) @_formatters = {} formatter_map.each do |type, formatters| register_formatter(type, *Array(formatters)) end end |
Instance Method Details
#formatter_for_type(type) ⇒ Object
22 23 24 |
# File 'lib/hammer_cli/output/formatters.rb', line 22 def formatter_for_type(type) @_formatters[type.name.split('::').last.to_sym] end |
#register_formatter(type, *formatters) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/hammer_cli/output/formatters.rb', line 14 def register_formatter(type, *formatters) if @_formatters[type].nil? @_formatters[type] = FormatterContainer.new(*formatters) else formatters.each { |f| @_formatters[type].add_formatter(f) } end end |