Class: ConfCtl::Cli::OutputFormatter
- Inherits:
-
Object
- Object
- ConfCtl::Cli::OutputFormatter
- Defined in:
- lib/confctl/cli/output_formatter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(objects, cols = nil, header: true, sort: nil, layout: nil, empty: '-', color: false) ⇒ OutputFormatter
constructor
A new instance of OutputFormatter.
- #print ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(objects, cols = nil, header: true, sort: nil, layout: nil, empty: '-', color: false) ⇒ OutputFormatter
Returns a new instance of OutputFormatter.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/confctl/cli/output_formatter.rb', line 15 def initialize(objects, cols = nil, header: true, sort: nil, layout: nil, empty: '-', color: false) @objects = objects @header = header @sort = sort @layout = layout @empty = empty @color = color if @layout.nil? @layout = if many? :columns else :rows end end if cols @cols = parse_cols(cols) elsif @objects.is_a?(::Array) if @objects.count == 0 @cols = [] else @cols ||= parse_cols(@objects.first.keys) end elsif @objects.is_a?(::Hash) # Single item @cols ||= parse_cols(@objects.keys) else raise "unsupported type #{@objects.class}" end end |
Class Method Details
.print(*args, **kwargs) ⇒ Object
10 11 12 13 |
# File 'lib/confctl/cli/output_formatter.rb', line 10 def self.print(*args, **kwargs) f = new(*args, **kwargs) f.print end |
.to_s(*args) ⇒ Object
5 6 7 8 |
# File 'lib/confctl/cli/output_formatter.rb', line 5 def self.to_s(*args) f = new(*args) f.to_s end |
Instance Method Details
#print ⇒ Object
56 57 58 59 |
# File 'lib/confctl/cli/output_formatter.rb', line 56 def print @out = nil generate end |
#to_s ⇒ Object
50 51 52 53 54 |
# File 'lib/confctl/cli/output_formatter.rb', line 50 def to_s @out = '' generate @out end |